Skip to content

[Fusion] Let NativeAOT inline the value completion fast paths - #10891

Merged
michaelstaib merged 3 commits into
mainfrom
perf/aot-value-completion
Nov 13, 2026
Merged

michaelstaib merged 3 commits into
mainfrom
perf/aot-value-completion

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

Value completion's hot helpers were just over the size where NativeAOT, which has no PGO, inlines them, so every completed property and list element paid several calls. This splits them into small inline fast paths with NoInlining cold paths for chunk-crossing cursor moves and raw reads, raw object contexts, selection set resolution and enum completion. The cursor's cold path is static, so inlined cursor arithmetic keeps cursor locals in registers. Responses are byte-identical (same sha256) and allocations are unchanged. With a static PGO profile for the AOT build the gain shrinks to +0.3% req/s (CPU per request 0.758 to 0.747 ms).

Metric Before Optimization After Optimization
Constant-latency req/s (AOT) 3,337 3,392 (+1.6%)
Constant-latency p50 / p95 (AOT) 13.95 / 19.42 ms 13.70 / 19.10 ms
Constant req/s (AOT) 4,795 4,911 (+2.4%)
CPU per request, constant-latency (AOT) 0.789 ms 0.754 ms (-4.4%)
Allocated per operation (AOT harness, alias / deep) 14,131 / 17,443 B 14,131 / 17,443 B
RSS avg / max under load, constant-latency (AOT) 98.4 / 100.9 MB 96.6 / 99.9 MB
Idle RSS (AOT) 51.4-51.8 MB 51.4 MB
Startup to first response (AOT) 76 ms 76 ms
Binary size (AOT) 42,636,832 B 42,604,032 B
Constant-latency req/s (JIT) 3,381 3,409 (+0.8%)
Constant req/s (JIT) 4,975 4,990 (+0.3%)
Allocated per request (JIT) 24,892 B 24,883 B
Constant-latency req/s (AOT, with a static PGO profile) 3,351 3,361 (+0.3%)

Measured with k6 on the benchmark twin (16.7.0 subgraphs, socket and Kestrel inline settings on, OptimizationPreference default), base and change interleaved ABBA, medians of 4 rounds (2 for constant-latency JIT and static PGO).

NativeAOT compiles without profile data and keeps small helpers out of line
when their IL is just over its inlining budget. Split the value completion
helpers into a small fast path and a non-inlined slow path (cursor moves
across chunks, raw object contexts, raw object property lookup, selection set
resolution, raw values that span data chunks) and mark the fast paths and the
tiny accessors they use for inlining. Small selection sets are searched with a
compact loop instead of an unrolled switch, so the lookup stays small at every
inlined call site.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 20:49

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 insufficient remaining quota.

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

79.4% of changed lines covered (54/68)

File Covered Changed Patch %
…/src/Fusion.Execution/Text/Json/CompositeObjectContext.cs 6 13 46.2% 🔴
…/Fusion.Execution/Text/Json/CompositeResultDocument.Cursor.cs 5 7 71.4% 🔴
…/Fusion.Execution/Text/Json/SourceResultDocument.Cursor.cs 5 7 71.4% 🔴
…/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs 6 7 85.7% 🟡
…/Text/Json/CompositeResultDocument.TryGetProperty.cs 13 15 86.7% 🟡
…/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSet.cs 7 7 100.0% 🟢
…/Fusion.Execution/Text/Json/CompositeResultDocument.DbRow.cs 2 2 100.0% 🟢
…/Text/Json/SourceElementSnapshotEnumerator.cs 1 1 100.0% 🟢
…/Text/Json/SourcePropertySnapshotEnumerator.cs 2 2 100.0% 🟢
…/src/Fusion.Execution/Text/Json/SourceResultDocument.cs 6 6 100.0% 🟢
…/Fusion.Execution/Text/Json/SourceResultElementSnapshot.cs 1 1 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "d64ef72c8c393782728d5a69e1e6383bf85e5871",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/CompositeObjectContext.cs", "ranges": [[61, 61], [69, 69], [71, 75]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/CompositeResultDocument.Cursor.cs", "ranges": [[214, 215]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/SourceResultDocument.Cursor.cs", "ranges": [[185, 186]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs", "ranges": [[298, 298]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Text/Json/CompositeResultDocument.TryGetProperty.cs", "ranges": [[416, 417]] }
  ]
}

Project coverage: 59.8% (326986/546561 lines)

@michaelstaib
michaelstaib merged commit 13467f6 into main Nov 13, 2026
159 checks passed
@michaelstaib
michaelstaib deleted the perf/aot-value-completion branch November 13, 2026 07:57
This was referenced Nov 17, 2026
This was referenced Nov 23, 2026
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