Skip to content

stop copying the error list on every add in ExecutionContext - #4532

Merged
bbakerman merged 1 commit into
graphql-java:masterfrom
nab-iha3:execution-context-error-list
Nov 4, 2026
Merged

bbakerman merged 1 commit into
graphql-java:masterfrom
nab-iha3:execution-context-error-list

Conversation

@nab-iha3

@nab-iha3 nab-iha3 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

{ items(n: N) { b0: bad b1: bad ... b999: bad } }, 9.9 KB, where the Item.bad fetcher throws (JDK 25, -Xmx4g):

field errors     before        after
     160,000     9,017 ms     2,361 ms
     320,000   154,313 ms     3,808 ms

ExecutionContext.addError and addErrors append by building a new ImmutableList from the old one plus the new error, so collecting N field errors costs N^2/2 element copies into freshly allocated arrays. the error count is set by the request: aliases of any field that errors (an auth check rejecting an anonymous caller, a fetcher rejecting its arguments) times the length of the list above it, so a ~10 KB query can keep an executor thread busy for minutes. a plain loop of 200,000 addError calls takes 75 s before and 0.56 s after on a 1 GB heap.

errors now go into an ArrayList guarded by the existing errorsLock, and getErrors() returns an ImmutableList copy taken under the same lock. it is only read when results are assembled, and callers still get an immutable snapshot. the new ExecutionContextTest case adds 200,000 errors under @Timeout(10): it times out before the change (84 s) and passes in 1.5 s after.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6179 (+1 🟢) 6123 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6179 (+1 🟢) 6123 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6179 (+1 🟢) 6123 (+1 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 18569 (+3 🟢) 18401 (+3 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30319 3083 90.8% ±0.0%
Branches 8954 1506 85.6% ±0.0%
Methods 8094 1189 87.2% ±0.0%

Changed Class Coverage (1 class)

Class Line Branch Method
g.c.ImmutableKit -1.4% 🔴 ±0.0% -6.7% 🔴
ImmutableKit — method details
Method Line Branch
concatLists 0.0% (-100.0% 🔴) —

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-03 07:21:06 UTC

@bbakerman bbakerman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@bbakerman
bbakerman merged commit f60aa96 into graphql-java:master Nov 4, 2026
7 of 9 checks passed
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