Skip to content

Resolve Fusion abstract types via allocation-free ASCII byte lookup#10150

Open
michaelstaib wants to merge 1 commit into
mainfrom
mst/fusion-typename-ascii-lookup
Open

Resolve Fusion abstract types via allocation-free ASCII byte lookup#10150
michaelstaib wants to merge 1 commit into
mainfrom
mst/fusion-typename-ascii-lookup

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 26, 2026 21:43

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.

Pull request overview

This pull request optimizes Fusion runtime type resolution by avoiding string materialization for __typename where possible, introducing UTF-8 span-based type lookup and an MRU memoization path for abstract type resolution.

Changes:

  • Add FusionTypeDefinitionCollection overloads to resolve types from raw UTF-8 bytes (with FrozenDictionary alternate lookup on newer runtimes).
  • Update execution-time abstract type resolution (ValueCompletion) to use AssertUtf8String() + MRU memoization and span-based schema lookup.
  • Adjust/extend tests and add benchmarks to measure span-based type lookup and memoized abstract type resolution.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Text/Json/SourceResultDocumentTests.cs Removes TryGetRawStringValue tests; should now cover AssertUtf8String.
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Types/FusionTypeDefinitionCollectionTests.cs Adds tests for the new span-based type lookup APIs.
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Results/FetchResultStoreTests.cs Adds regression coverage for abstract type fallback schema lookup when implementer count exceeds the lookup limit.
src/HotChocolate/Fusion/test/Fusion.AspNetCore.Tests/UnionTests.cs Updates expectations for escaped __typename handling in unions.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/SourceResultElementSnapshot.cs Adds AssertUtf8String() to snapshot API and removes TryGetRawStringValue.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/SourceResultElement.cs Adds AssertUtf8String() to element API and removes TryGetRawStringValue.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/SourceResultDocument.Text.cs Removes TryGetRawStringValue implementation from document text helpers.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/ValueCompletion.cs Switches schema type to FusionSchemaDefinition, adds MRU memo, and uses UTF-8 span lookup for abstract type resolution.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/FetchResultStore.Pooling.cs Updates initialization to use FusionSchemaDefinition.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Results/FetchResultStore.cs Updates stored schema field type to FusionSchemaDefinition.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanContext.Pooling.cs Casts request schema to FusionSchemaDefinition when initializing the result store.
src/HotChocolate/Fusion/src/Fusion.Execution.Types/Collections/FusionTypeDefinitionCollection.cs Implements span-based GetType/TryGetType overloads with optimized NET9 alternate lookup.
src/HotChocolate/Fusion/benchmarks/Fusion.Execution.Benchmarks/SpanTypeLookupBenchmark.cs Adds benchmark for span-based schema type lookup to validate allocation improvements.
src/HotChocolate/Fusion/benchmarks/Fusion.Execution.Benchmarks/AbstractTypeResolutionMemoBenchmark.cs Updates benchmark to reflect AssertUtf8String + span-keyed lookup path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +296 to +304
public ReadOnlySpan<byte> AssertUtf8String()
{
if (ValueKind is not JsonValueKind.String)
{
throw new InvalidOperationException("The element value is null.");
}

return ValueSpan;
}
Comment on lines +263 to +271
public ReadOnlySpan<byte> AssertUtf8String()
{
if (ValueKind is not JsonValueKind.String)
{
throw new InvalidOperationException("The element value is null.");
}

return ValueSpan;
}
Comment on lines 1293 to +1295
// Small implementer sets resolve the type by comparing the raw UTF-8 __typename
// bytes, which is allocation free. Beyond 4 candidates the linear scan loses to
// the dictionary lookup, so larger sets, escaped values, non-string values, and
// values that span document chunks use the existing fallback below.
// the dictionary lookup, so larger sets use the memo below.
Comment on lines 594 to 595
[Fact]
public void TryGetProperty_EscapedPropertyNames_WorksCorrectly()
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