Skip to content

Make operation validation iterative and fix fragment-chain stack overflows - #4545

Merged
andimarek merged 3 commits into
masterfrom
codex/iterative-operation-validation
Nov 8, 2026
Merged

andimarek merged 3 commits into
masterfrom
codex/iterative-operation-validation

Conversation

@andimarek

@andimarek andimarek commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

A valid operation can pass the default parser limits yet overflow a 1 MiB Java thread stack when it follows 1,501 fragment definitions, even with only two field levels.

Changes

  • Give OperationValidator one iterative validate() entry point for AST traversal and operation-scoped fragment expansion. Remove LanguageTraversal and DocumentVisitor; migrate tests and benchmarks.
  • Make fragment-reference scanning, used-fragment discovery and merge-validation field collection iterative. Update the execution field collector too, covering subscription validation and execution.
  • Preserve validation order, ancestor paths, per-operation variable checks, field/depth counts, selection order and @defer scope.
  • Reduce temporary allocations: reuse singleton parent groups and collection stacks, and avoid traversal frames for already-expanded fragment spreads while retaining their complexity counts and directive checks.
  • Add long-chain and deeply nested programmatic-AST regressions, plus coverage for sibling fragment collection, nested merge conflicts and repeated-spread error ordering.

Validation

  • ./gradlew test check: 6,095 tests, 7 expected skips, no failures; build checks pass.
  • 559 focused tests pass with -Xss1m, including the fragment-stack regressions.
  • On unmodified master, 14 of the original 15 stack regression cases fail with StackOverflowError; all pass with this change.

Performance

The existing GoodFaithValidationBenchmark.validate with scenario=fragmentHeavy validates 1,000 aliased selections using shared nested fragments. Parsing and schema construction are outside the timed method.

Hetzner Ryzen 5 3600; Java 25, ZGC, fixed 4 GiB heap and 1 MiB stack. Identical dependencies and benchmark bytecode; three forks per version, 10 × 10-second warmup and 5 × 10-second measurement iterations, with the JMH GC profiler. CPU/allocation profiles were recorded separately.

Per validation Master d5e7c26c3 With this PR Change
Time 1.564 ms 1.336 ms −14.6%
Allocation 4.459 MB 2.643 MB −40.7%

These are the final runs after three profiling/optimization rounds, including a fresh baseline run. Every candidate fork averaged faster than every baseline fork. This measures one validation workload; it does not measure execution-side field collection or establish results for every query.

@andimarek
andimarek marked this pull request as ready for review November 7, 2026 23:43
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6285 (+23 🟢) 6229 (+23 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6285 (+23 🟢) 6229 (+23 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6285 (+23 🟢) 6229 (+23 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 18887 (+69 🟢) 18719 (+69 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30449 3077 90.8% ±0.0%
Branches 9010 1504 85.7% +0.1% 🟢
Methods 8118 1186 87.3% ±0.0%

Changed Class Coverage (7 classes)

Class Line Branch Method
g.e.FieldCollector +0.2% 🟢 +0.5% 🟢 ±0.0%
g.u.SelectionSetTraversalFrame +100.0% 🟢 +100.0% 🟢 +100.0% 🟢
g.v.LanguageTraversal removed removed removed
g.v.OperationValidationFrame +97.3% 🟢 +90.0% 🟢 +100.0% 🟢
g.v.OperationValidator +0.2% 🟢 +0.1% 🟢 ±0.0%
g.v.OperationValidator
$1
removed removed removed
g.v.Validator +4.3% 🟢 ±0.0% +11.1% 🟢

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-08 02:36:48 UTC

@andimarek
andimarek merged commit 5b1a5f4 into master Nov 8, 2026
10 checks passed
@andimarek andimarek added this to the 27 milestone Nov 11, 2026
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.

1 participant