Resolve Fusion abstract types via allocation-free ASCII byte lookup#10150
Open
michaelstaib wants to merge 1 commit into
Open
Resolve Fusion abstract types via allocation-free ASCII byte lookup#10150michaelstaib wants to merge 1 commit into
michaelstaib wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
FusionTypeDefinitionCollectionoverloads to resolve types from raw UTF-8 bytes (withFrozenDictionaryalternate lookup on newer runtimes). - Update execution-time abstract type resolution (
ValueCompletion) to useAssertUtf8String()+ 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.