Skip to content

Materialize Fusion result objects from selection-set row templates - #10139

Merged
michaelstaib merged 3 commits into
mainfrom
mst/fusion-selectionset-object-templates
Jul 22, 2026
Merged

Materialize Fusion result objects from selection-set row templates#10139
michaelstaib merged 3 commits into
mainfrom
mst/fusion-selectionset-object-templates

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 22, 2026 14:21

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 PR optimizes Fusion JSON result materialization by introducing an operation-shared, selection-set-level “object row template” and a new MetaDb bulk-append path that copies/stamps prebuilt object blocks (including correct per-request exclusion stamping) instead of appending rows one-by-one.

Changes:

  • Add ObjectTemplate built during SelectionSet.Seal() and reuse it when creating object instances.
  • Add MetaDb.AppendObjectBlock(...) with fast-path (single chunk) and spanning-path (multi-chunk) implementations, stamping parent pointers and per-request exclusion.
  • Add targeted regression/geometry tests for chunk-boundary behavior and “template leakage” across include/defer permutations.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Text/Json/CompositeResultDocumentTests.cs Adds regression tests covering chunk-splits, shared-template correctness, and include/defer leakage scenarios.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/CompositeResultDocument.MetaDb.cs Adds AppendObjectBlock and spanning implementation to copy/stamp object blocks efficiently across chunks.
src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/CompositeResultDocument.cs Switches object materialization to template-based block append; computes per-request excluded property-row offsets.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSet.cs Builds and stores the per-selection-set ObjectTemplate during seal.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs Exposes CanBeDeferred used to decide whether exclusion is request-dependent for a selection.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/ObjectTemplate.cs New type that precomputes canonical object row blocks and tracks conditional/deferrable selection indices.

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

Comment on lines +438 to +440
var conditionalSelections = template.ConditionalSelections;
Span<int> excludedRowOffsets = stackalloc int[conditionalSelections.Length];
var excludedCount = 0;
ref MemoryMarshal.GetReference(template),
(uint)template.Length);

// The trailing EndObject row keeps its template parent of zero.
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (205/205)

File Covered Changed Patch %
…/src/Fusion.Execution/Execution/Nodes/ObjectTemplate.cs 69 69 100.0% 🟢
…/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs 1 1 100.0% 🟢
…/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSet.cs 2 2 100.0% 🟢
…/Fusion.Execution/Text/Json/CompositeResultDocument.MetaDb.cs 114 114 100.0% 🟢
…/src/Fusion.Execution/Text/Json/CompositeResultDocument.cs 19 19 100.0% 🟢

Project coverage: 53.8% (231652/430539 lines)

@michaelstaib
michaelstaib merged commit 3770b88 into main Jul 22, 2026
78 checks passed
@michaelstaib
michaelstaib deleted the mst/fusion-selectionset-object-templates branch July 22, 2026 22:45
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