Skip to content

Reduce allocations during variable coercion - #10097

Merged
michaelstaib merged 2 commits into
mainfrom
mst/variable-alloc
Jul 12, 2026
Merged

michaelstaib merged 2 commits into
mainfrom
mst/variable-alloc

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 12, 2026 12:19

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 JSON variable coercion in Fusion execution to reduce allocations, while adding regression tests to ensure error paths, depth limits, OneOf validation, and numeric lexeme preservation remain correct.

Changes:

  • Reworks JsonVariableCoercion to defer path construction via an inline path-segment buffer and only materialize Path/string representations on error.
  • Avoids number-token string/byte allocations by reading raw UTF-8 number lexemes via JsonMarshal.GetRawUtf8Value.
  • Adds tests covering nested variable error paths, OneOf error behavior, max-depth boundary enforcement, and numeric lexeme/format preservation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/VariableCoercionHelperTests.cs Adds regression tests for nested paths, OneOf, max depth, and numeric lexeme preservation.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/JsonVariableCoercion.cs Implements allocation reductions via deferred path segments and raw UTF-8 numeric parsing.

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

Comment on lines +213 to +220
CoerceError(
schema,
variableDefinition,
"""{"input":{"items":[{"id":1},{}]}}"""),
CoerceError(
schema,
variableDefinition,
"""{"input":{"items":[{"id":1,"unknown":"wrong"}]}}""")
@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

90.4% of changed lines covered (85/94)

File Covered Changed Patch %
…/src/Fusion.Execution/Execution/JsonVariableCoercion.cs 85 94 90.4% 🟡
Uncovered changed lines (JSON)
{
  "sha": "fefcac82f49f5241450eb3174b9de01aa46bff26",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/JsonVariableCoercion.cs", "ranges": [[89, 89], [216, 216], [395, 395], [433, 433], [445, 445], [577, 578], [587, 588]] }
  ]
}

Project coverage: 53.7% (230153/428802 lines)

@michaelstaib
michaelstaib merged commit d30d2d5 into main Jul 12, 2026
147 checks passed
@michaelstaib
michaelstaib deleted the mst/variable-alloc branch July 12, 2026 12: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