-
-
Notifications
You must be signed in to change notification settings - Fork 799
[Fusion] Improve OperationCompiler performance #8823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes OperationCompiler performance by removing the InlineFragmentOperationRewriter and refactoring method signatures to work directly with operations instead of full documents.
Key changes:
- Removes InlineFragmentOperationRewriter from OperationCompiler since documents are already rewritten when compiling
- Changes DocumentRewriter.RewriteDocument to return OperationDefinitionNode directly via RewriteOperation
- Adds benchmarks for OperationCompiler, DocumentRewriter, and OperationPlanner
Reviewed Changes
Copilot reviewed 26 out of 32 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
DocumentRewriter.cs | Changed method signature to return OperationDefinitionNode directly and improved field comparison logic |
OperationCompiler.cs | Removed InlineFragmentOperationRewriter dependency and redundant document rewriting |
OperationPlanner.cs | Added TryCreatePlan method and improved selection inlining with deduplication |
Various test files | Updated method calls to use new RewriteOperation signature |
Benchmark files | Added new benchmark classes for performance testing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Planning/OperationPlanner.cs
Show resolved
Hide resolved
src/HotChocolate/Fusion-vnext/src/Fusion.Utilities/Rewriters/DocumentRewriter.cs
Show resolved
Hide resolved
if (seenSelections.Add(fieldWithDirective)) | ||
{ | ||
var insertIndex = newSelections.Count; | ||
var fieldName = field.Name.Value; | ||
|
||
for (var i = newSelections.Count - 1; i >= 0; i--) | ||
{ | ||
if (newSelections[i] is FieldNode existingField | ||
&& existingField.Name.Value.Equals(fieldName, StringComparison.Ordinal)) | ||
{ | ||
insertIndex = i + 1; | ||
break; | ||
} | ||
} | ||
|
||
newSelections.Insert(insertIndex, fieldWithDirective); |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reverse loop to find insertion index could be inefficient for large selection sets. Consider maintaining a dictionary mapping field names to their last index positions to avoid O(n) lookups for each insertion.
Copilot uses AI. Check for mistakes.
OperationCompiler
,DocumentRewriter
and the plan portion ofOperationPlanner
.DocumentRewriter
from OperationCompiler for improved performanceDocumentRewriter
is basically just sorting the inserted requirements at that point...