Skip to content

[Fusion] Look up input object fields by UTF-8 name during variable coercion - #10522

Open
tobias-tengler wants to merge 1 commit into
mainfrom
tte/fusion-utf8-input-field-lookup
Open

tobias-tengler wants to merge 1 commit into
mainfrom
tte/fusion-utf8-input-field-lookup

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Variable coercion allocated several objects for every field of an input object variable: JsonVariableCoercion read JsonProperty.Name up to three times per field (field lookup, error path segment and the coerced ObjectFieldNode), and each read decodes a new UTF-16 string. Every coerced field also got a new NameNode.

This PR looks input fields up by their raw UTF-8 property name. FusionInputFieldDefinitionCollection gets a TryGetField(ReadOnlySpan<byte>) overload, backed by the same sorted UTF-8 name index FusionEnumValueCollection already used (now shared as Utf8NameIndex). The coerced ObjectFieldNode reuses a NameNode cached on FusionInputFieldDefinition, and the error path uses the schema's field name. JSON allows escaping any character of a property name ({"\u0069d": 1} is a valid way to send id), so a property name containing an escape sequence falls back to the unescaped lookup, only when the UTF-8 lookup misses.

Benchmarks

Small input (2 objects, 5 fields)

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 792.3 ns 1.00 1.58 KB 1.00
Variable coercion PR 590.2 ns 0.74 0.95 KB 0.60

Large input with a list of 20 input objects (22 objects, 66 fields)

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 8.146 μs 1.00 17.09 KB 1.00
Variable coercion PR 5.074 μs 0.62 7.91 KB 0.46

Variable coercion allocates 40% less for the small input and 54% less for the large input, and is 26% and 38% faster, because each input field no longer allocates its name strings and NameNode.

@tobias-tengler
tobias-tengler force-pushed the tte/fusion-utf8-input-field-lookup branch 2 times, most recently from bd53aa7 to 4ca43dc Compare October 9, 2026 10:40
@tobias-tengler
tobias-tengler marked this pull request as ready for review October 9, 2026 10:41
Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The enum refactor introduces an avoidable array allocation for every enum collection.

1 open finding
What changed in this PR

Optimizes Fusion input-object variable coercion by matching raw UTF-8 property names and reusing cached syntax nodes.

Changes:

  • Adds a shared UTF-8 name index.
  • Uses UTF-8 lookup with escaped-name fallback.
  • Adds lookup and coercion coverage.
File Description
VariableCoercionHelperTests.cs Tests escaped JSON field names.
FusionInputFieldDefinitionCollectionTests.cs Tests UTF-8 field lookup.
JsonVariableCoercion.cs Uses UTF-8 lookup and cached names.
FusionInputFieldDefinition.cs Caches each field’s NameNode.
Utf8NameIndex.cs Implements shared UTF-8 indexing.
FusionInputFieldDefinitionCollection.cs Adds span-based field lookup.
FusionEnumValueCollection.cs Adopts the shared index.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (86/86)

File Covered Changed Patch %
…/Collections/FusionEnumValueCollection.cs 2 2 100.0% 🟢
…/Collections/FusionInputFieldDefinitionCollection.cs 10 10 100.0% 🟢
…/src/Fusion.Execution.Types/Collections/Utf8NameIndex.cs 58 58 100.0% 🟢
…/src/Fusion.Execution.Types/FusionInputFieldDefinition.cs 2 2 100.0% 🟢
…/src/Fusion.Execution/Execution/JsonVariableCoercion.cs 14 14 100.0% 🟢

Project coverage: 58.6% (314230/536486 lines)

…ercion

Variable coercion read `JsonProperty.Name` up to three times per input object
field and created a new `NameNode` for every coerced field. Fields are now looked
up by their raw UTF-8 property name and the coerced `ObjectFieldNode` reuses a
`NameNode` cached on the input field definition. Escaped property names fall
back to the unescaped lookup.
@tobias-tengler
tobias-tengler force-pushed the tte/fusion-utf8-input-field-lookup branch from 4ca43dc to 2fe2abb Compare October 9, 2026 10:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants