Skip to content

[Fusion] Write forwarded variable literals as UTF-8 - #10517

Merged
tobias-tengler merged 3 commits into
mainfrom
tte/fusion-utf8-variable-literals
Oct 9, 2026
Merged

tobias-tengler merged 3 commits into
mainfrom
tte/fusion-utf8-variable-literals

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

The gateway forwarded string and enum variables to source schemas through UTF-16 strings: variable coercion called JsonElement.GetString() for every value, and FetchResultStore transcoded those strings back to UTF-8 when writing the source schema request.

This PR keeps forwarded variables in UTF-8. JsonVariableCoercion copies the raw UTF-8 bytes of string and enum values into the request's Utf8MemoryBuilder (unescaping them when the JSON string contains escape sequences) and creates segment-backed StringValueNode and EnumValueNode literals. FetchResultStore writes string, enum, int and float literals from their UTF-8 spans, so no strings are created for forwarded variables.

Benchmarks

Enums (21 enum values)

Method Version Mean Ratio Allocated Alloc Ratio
Gateway request main 20.04 μs 1.00 31.55 KB 1.00
Gateway request PR 19.47 μs 0.97 31.03 KB 0.98
Variable coercion main 1.310 μs 1.00 2.59 KB 1.00
Variable coercion PR 1.215 μs 0.93 2.04 KB 0.79

256 character strings (21 values)

Method Version Mean Ratio Allocated Alloc Ratio
Gateway request main 21.84 μs 1.00 41.91 KB 1.00
Gateway request PR 21.70 μs 0.99 36.25 KB 0.86
Variable coercion main 2.279 μs 1.00 13.03 KB 1.00
Variable coercion PR 2.308 μs 1.01 7.34 KB 0.56

16 KB lorem ipsum string (1 value)

Method Version Mean Ratio Allocated Alloc Ratio
Gateway request main 23.82 μs 1.00 61.35 KB 1.00
Gateway request PR 22.33 μs 0.94 45.38 KB 0.74
Variable coercion main 2.294 μs 1.00 32.48 KB 1.00
Variable coercion PR 2.165 μs 0.94 16.51 KB 0.51

Gateway requests allocate 2% less with enum variables, 14% less with 256 character strings and 26% less with a 16 KB string, because each forwarded string value is no longer held as a UTF-16 string. With the 16 KB string, the gateway request is also 6% faster. The other time differences are within the measurement error (about ±0.2 to ±0.5 μs for gateway requests).

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

77.8% of changed lines covered (35/45)

File Covered Changed Patch %
…/src/Fusion.Execution/Execution/JsonVariableCoercion.cs 31 41 75.6% 🔴
…/src/Fusion.Execution/Execution/Results/FetchResultStore.cs 4 4 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "7e7e55ef636f9b001713427c67693958eb5815bc",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/JsonVariableCoercion.cs", "ranges": [[477, 477], [479, 487]] }
  ]
}

Project coverage: 58.6% (314214/536401 lines)

@tobias-tengler
tobias-tengler marked this pull request as ready for review October 9, 2026 06:10
Copilot AI balanced review requested due to automatic review settings October 9, 2026 06:10

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.

🟡 Changes recommended

An unused import will fail CI, and forwarded UTF-8 serialization lacks direct regression coverage.

2 open findings
What changed in this PR

Updates Fusion to preserve forwarded variable literals as UTF-8 through coercion and serialization.

Changes:

  • Stores coerced strings and enums as UTF-8.
  • Writes value-node spans directly to JSON.
  • Adds escape-sequence coercion tests.
File Description
VariableCoercionHelperTests.cs Tests escaped strings and enums.
FetchResultStore.cs Serializes value nodes directly from UTF-8 spans.
JsonVariableCoercion.cs Coerces JSON strings and enums into UTF-8-backed nodes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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