Skip to content

perf: reduce allocation for execution result maps - #4919

Open
jhonDoe15 wants to merge 1 commit into
graphql:17.x.xfrom
jhonDoe15:perf/compact-execution-results
Open

jhonDoe15 wants to merge 1 commit into
graphql:17.x.xfrom
jhonDoe15:perf/compact-execution-results

Conversation

@jhonDoe15

@jhonDoe15 jhonDoe15 commented Oct 27, 2026 •

Copy link
Copy Markdown

Summary

Dense execution results allocate a null-prototype map for each completed object. Use a shared empty constructor before removing the prototype at the two hot allocation sites:

- Object.create(null)
+ Object.setPrototypeOf(new CompactExecutionResultMap(), null)

Results remain fresh, mutable, null-prototype objects. Tests cover synchronous/asynchronous completion, prototype-like aliases, descriptors and independent results. Request-setup maps and serial mutation execution are unchanged. This uses the same allocation approach as GraphQL Tools #8610.

Evidence

Actual source patch versus c93662d, Node 24.22.1 / Windows x64, five fresh paired processes, identical 100 MB responses:

Metric Base median PR median Median paired reduction
Request-added heap 1,134.22 MB 529.14 MB 53.35%
Peak RSS 1,413.34 MB 792.79 MB 43.91%
Execution elapsed 4.35 s 3.65 s 10.51%
Execution + serialization/encoding/hash 6.46 s 4.49 s 28.00%

Idle heap is approximately 13.7 MB; input-ready heap is 219.3 MB on both sides. Input remains live. Heap is sampled at phase checkpoints; RSS includes process startup. No mid-execution GC or profiler. This is a dense small-object workload, not a universal memory claim.

The 25 MB pilot improves added heap by 55.40%, but execution alone is 9.40% slower. The promise-heavy 3 MB case improves added heap by only 7.83% and RSS by 4.01%. Timing varies; every 100 MB pair improves the tabled metrics.

An additional 40 paired trials cover 1/8/32/100-field objects on Node and Bun. Node's retained-output saving is about 79% for 1/8 fields, but essentially zero for 32/100 fields; 32-field execution is 5.56% slower. Bun 1.3.14 shows no consistent memory benefit: 8-field execution is 3.36% slower and 32-field RSS is 5.36% higher. These are workload/engine tradeoffs for review, with short, variable timings; full matrix and methodology.

Reproduction scripts, protocol and raw paired results are kept outside this PR's diff.

Validation on Linux/Node 24.19.0: 3,112 source tests with 100% line/branch/function coverage, 360 examples, 11 fuzz tests, repository lint/types/formatting/spelling, npm/Deno builds and the Deno package check all pass. The new regression cases also pass on Bun 1.3.14.

The unchanged integration harness passes 17 cases; 12 fail at unavailable Docker launches. All 15 subsequent direct Node/Bun/Deno commands pass using Node 24.19.0 and the repository's pinned Bun 1.2.18 / Deno 2.4.1. Full container/version-matrix checks remain for CI. The earlier Windows Deno-path/CRLF issues pass in the clean Linux checkout. Validation details and logs.

Merge Danger

Door: two-way.

Blast Radius: execution.

No intended observable result change. The memory benefit depends on engine object layout and result shape; the wider-object and Bun tradeoffs above need maintainer assessment before merge.

@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown

@jhonDoe15 is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: jhonDoe15 / name: JhonDoe15 (11f2b7a)

@jhonDoe15
jhonDoe15 marked this pull request as ready for review October 27, 2026 09:41
@yaacovCR

Copy link
Copy Markdown
Contributor

@jhonDoe15 @ardatan

This is really interesting. I think we here at graphql-js don't want to get in the way of any users hoping to perform optimization for their engines, but I also don't quite know what to expect here in terms of maintainability. How long will this techinque work for? Will it have to be reassessed for every engine?

I wonder if we could try to provide an execution arg for passing a function that creates the empty record object in the manner of our users' choosing? would that extra function cause too much overhead? If this would work, it would allow the graphql tools executor to eventually migrate back to graphql-js if they so choose without losing this performance win.

@benjie I know we discusses previously the importance of null prototypes => an advanced option such as the above would also presumably allow users to forgo null prototypes at their peril, although of course, that would have to be done on purpose.

Thanks again!

@yaacovCR

yaacovCR commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Just highlighting that in my own testing, that this optimization for Node/Deno (V8) is a regression for Bun (JavaScriptCore). This argues strongly in favor of allowing this to be configurable, although we could set the default to V8...

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants