Skip to content

Look up input object fields and enum values by UTF-8 name during variable coercion - #10534

Merged
tobias-tengler merged 2 commits into
mainfrom
tte/core-utf8-input-field-lookup
Oct 13, 2026
Merged

tobias-tengler merged 2 commits into
mainfrom
tte/core-utf8-input-field-lookup

Conversation

@tobias-tengler

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

Copy link
Copy Markdown
Member

Variable coercion decoded every JSON property name and enum string into a UTF-16 string for the field and value lookups, and the literal pass created a new NameNode per coerced field.

FieldCollection<T> and EnumValueCollection now look names up as UTF-8 bytes: collections with up to eight entries are scanned with Ascii.Equals, larger ones widen the name into a stack buffer and use the frozen dictionary's ReadOnlySpan<char> alternate lookup. The enum lookup honors the configurable name comparer and only decodes the string for custom comparers. The input parser and the coercion helper use these lookups, the literal pass reuses the schema's enum name and a NameNode cached on InputField, and processed fields are tracked by index instead of a pooled string set.

Benchmarks

Measured with a local VariableCoercionBenchmark (not part of this PR), net11 in-process.

Small input (2 objects, 5 fields)

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 1.312 μs 1.00 3.33 KB 1.00
Variable coercion PR 0.995 μs 0.76 2.31 KB 0.69

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

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 15.979 μs 1.00 36.09 KB 1.00
Variable coercion PR 11.870 μs 0.74 24.13 KB 0.67

Single enum value

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 133.5 ns 1.00 480 B 1.00
Variable coercion PR 132.7 ns 0.99 416 B 0.87

List of 20 enum values (12-value enum)

Method Version Mean Ratio Allocated Alloc Ratio
Variable coercion main 1.947 μs 1.00 5,200 B 1.00
Variable coercion PR 2.118 μs 1.09 3,632 B 0.70

Variable coercion allocates 31% less for the small input and 33% less for the large input, and is 24% and 26% faster. A single enum value allocates 13% less at the same speed. A list of 20 values of a 12-value enum allocates 30% less but is 9% slower, because the hashed lookup fetches the alternate lookup per call; caching it, together with a cached enum literal, follows in a separate PR.

…able coercion

Variable coercion decoded every JSON property name and enum string into a
UTF-16 string for the field and value lookups, and the literal pass created a
new NameNode per coerced field.

FieldCollection<T> and EnumValueCollection now look names up as UTF-8 bytes:
collections with up to eight entries are scanned with Ascii.Equals, larger
ones widen the name into a stack buffer and use the frozen dictionary's
ReadOnlySpan<char> alternate lookup. The enum lookup honors the configurable
name comparer and only decodes the string for custom comparers. The input
parser and the coercion helper use these lookups, the literal pass reuses the
schema's enum name and a NameNode cached on InputField, and processed fields
are tracked by index instead of a pooled string set.
@tobias-tengler
tobias-tengler force-pushed the tte/core-utf8-input-field-lookup branch from 39fcf1e to d7f22f0 Compare October 13, 2026 12:49
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (95/95)

File Covered Changed Patch %
…/src/Types/Execution/Processing/VariableCoercionHelper.cs 15 15 100.0% 🟢
src/HotChocolate/Core/src/Types/Types/EnumType.cs 9 9 100.0% 🟢
src/HotChocolate/Core/src/Types/Types/EnumValueCollection.cs 25 25 100.0% 🟢
src/HotChocolate/Core/src/Types/Types/FieldCollection.cs 21 21 100.0% 🟢
src/HotChocolate/Core/src/Types/Types/InputField.cs 2 2 100.0% 🟢
src/HotChocolate/Core/src/Types/Types/InputParser.cs 23 23 100.0% 🟢

Project coverage: 58.7% (315762/538284 lines)

The JSON property and element overloads move into the input parser and the
enum type, the enum collection's byte lookup mirrors the field collection,
and the literal pass allocates the enum value node per coerced value from
the schema's name.
@tobias-tengler
tobias-tengler marked this pull request as ready for review October 13, 2026 13:11
Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:11

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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