GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reduce SDL checking, directive construction, and schema traversal work by andimarek · Pull Request #4535 · graphql-java/graphql-java

Conversation

@andimarek

@andimarek andimarek commented Nov 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR reduces SDL checking, directive construction and shared traversal work during
schema generation. The direct IDL follow-up below affects both SchemaGenerator
and FastSchemaGenerator through the checker and construction helpers they call.

Direct SDL checking and construction changes

Change Previous work New behavior
SchemaTypeChecker.checkFieldTypesPresent Copied field types into a list and built nested argument-type lists before flattening them. Visits the existing fields and arguments directly, in two passes that retain the existing error order.
SchemaTypeChecker.checkNamedUniqueness Allocated a set for empty/single-item lists and performed separate membership and insertion lookups. Returns immediately for fewer than two entries and uses the result of Set.add to identify duplicates.
ImplementingTypesChecker Built a field set/map even when no interfaces were implemented; printed both argument-type ASTs to compare them. Skips the field map after resolving an empty interface set, and compares type names/list/non-null wrappers directly. AST printing remains on error-reporting paths.
SchemaTypeDirectivesChecker Rebuilt a directive's allowed-argument map for every use. Reuses that map within one checker instance. Supplied values are still validated independently at each use.
SchemaGeneratorHelper.BuildContext Scanned the runtime directive-definition set for each applied directive. Maintains a per-build name index, preserving first-definition lookup behavior and the existing AST fallback for forward definitions.
SchemaGeneratorAppliedDirectiveHelper Built two supplied-argument maps and four temporary argument lists/copies while constructing legacy and applied directives. Inserts supplied arguments into the builders directly, shares one supplied-name set while adding missing/default arguments, and skips output-list allocation for empty directive lists.

TypeDefinitionRegistry is unchanged in this follow-up: the existing registry
improvements are already in the baseline, and the profiles supported the checker
and directive-construction changes above.

Final incremental mean time reduction versus follow-up baseline baf539554
(the previous PR plus master 96443c271; the same master correctness fixes are
present in both variants). Positive means less time; negative means more:

Fixture SchemaGenerator: generation Fast: generation SchemaGenerator: parse + generation Fast: parse + generation
1 +16.94% +25.77% +10.34% +15.64%
2 +26.64% +43.04% +19.70% +26.15%
3 +2.51% +7.18% -0.23% +3.15%
4 +2.08% +8.25% +2.94% +4.49%
5 +3.49% +4.63% +1.18% +3.07%

Allocation per operation is lower in all 20 cases, by 1.62-61.84%. Time means
are lower in 19/20. SchemaGenerator parsing fixture 3 is 0.23% slower, with
overlapping fork means and JMH intervals; no time gain is claimed for that case.
Timing intervals also overlap for SchemaGenerator fixture 4 in both scopes and
all fixture 5 cases. Those small gains are observed means, not separately
established significant improvements.

The two change groups were measured independently before the final comparison:

Exploratory comparison Lower time means Range of time reduction Lower allocation means
SDL checker group A versus baseline 18/20 -4.76% to +42.96% 16/20
Directive construction B2 versus A 16/20 -2.12% to +4.93% 16/20

These one-fork comparisons attribute results to groups, not individual edits,
and do not enter the final gains above. All ten Fast cases had lower time means
in the directive experiment. Unfavorable exploratory cases are retained: notably A's
SchemaGenerator fixture 5 slowdowns and B2's fixture 4/5 allocation increases
versus A. Separate profiles and repeated forks showed allocation variation in
unchanged traversal paths in both A and B2; JVM allocation elimination is a
possible explanation, not proven causation. The final combined comparison has
lower mean time/allocation in those cases, but does not independently disprove
every unfavorable A-versus-B2 difference.

Methodology: dedicated Ryzen 5 3600; Java 25 only, 24 GiB fixed heap, ZGC,
compact object headers, adaptive GC workers. All five fixtures, both generators,
both scopes: 20 timing cases, three forks/version/case, each with 10 x 10s warmup
and 5 x 10s measurement. Version order alternates by case; runs are serial under
a global lock. Nineteen separate async-profiler recordings used the same warmup
and 3 x 10s measurement; their timing scores are excluded. All 120 final timing
forks completed with zero allocation stalls. Two candidate warmup trends were
inspected and retained (SG generation fixture 4 and parsing fixture 5, fork 3);
their uncertainty is documented. Original governors and paused timer/service
states were restored and verified after measurement.

Correctness: 529 targeted IDL cases; full Java 25 ZGC/compact-header suite
6,146 passed, seven existing skips; all ten generated-schema hashes/type counts
match baseline; Javadoc and the per-class coverage gate passed. Local totals
include two unrelated untracked parser tests excluded from this PR. Spock tests
cover error order, wrapper comparisons, extensions, malformed interfaces,
directive defaults/nulls/unset values, both generators and options, ordering,
forward definitions and build isolation. CI passed Java 17/21/25 tests and TestNG, jcstress, Javadoc, build checks, file validation, and the per-class coverage gate.

Complete follow-up results, both exploratory tables, raw JMH/GC logs, profiles, limitations and reproduction.

The follow-up measurements are incremental to a newer baseline. Keep them
separate from the original results below; do not add or multiply percentages.

Original shared traversal changes and results

Both schema generators spend substantial time traversing schema elements and validating the resulting schema. This PR reduces allocation and repeated work in that shared code through four changes, developed over three profiling rounds:

  1. Create ancestor lists only when needed — DefaultTraverserContext. Previously, every traversal context copied its parent's complete ancestor list, even when the visitor never requested that list. Now it captures the parent breadcrumb and builds/caches the full immutable list on the first getBreadcrumbs() call. Traversals that do not need breadcrumbs avoid those list allocations and copies. Parent-node snapshots and custom context behavior are preserved.

  2. Create local variable maps only on the first write — TraverserState / DefaultTraverserContext. Previously, every non-root sequential traversal context allocated an empty LinkedHashMap. Now the map is allocated only when setVar() is called. Contexts that only read inherited state therefore need no local map; parent lookup and variable shadowing remain dynamic.

  3. Allocate the flattened child list at its final size — SchemaElementChildrenContainer.getChildrenAsList(). Previously, repeated addAll() calls grew the result array and created temporary arrays for child groups. Now the method sums the child counts, allocates the required capacity once, and appends children directly. This removes temporary arrays and growth copies while preserving order, duplicates, and an independent mutable result.

  4. Look up validation state only for nodes with directives — AppliedDirectivesAreValid. Previously, every visited node searched its ancestor contexts for the schema and error collector before checking whether it had directives. Now that check happens first. Nodes without directives avoid both ancestor searches; nodes with directives receive the same validation checks.

The JMH benchmarks now cover both generators, all five large schemas, and both generation-only and parsing-plus-generation, with schema validation enabled. Spock tests cover the behavior affected by these optimizations.

Final mean time reduction versus master b88bb44f5 (already includes #4528):

Fixture SchemaGenerator: generation Fast: generation SchemaGenerator: parse + generation Fast: parse + generation
1 7.75% 4.53% 5.53% 3.77%
2 6.26% 4.76% 4.27% 2.17%
3 12.01% 7.49% 7.46% 5.83%
4 15.87% 12.57% 10.66% 8.64%
5 21.54% 24.55% 16.91% 19.79%

Allocation per operation falls 2.48–30.32%. The 2.17% Fast/fixture-2 parsing gain has overlapping variability; it is not claimed as independently significant.

Measured serially on a dedicated Ryzen 5 3600 using Java 25, ZGC, compact headers, adaptive GC workers, and a 24 GiB heap. Final comparison: 3 forks/version/case, each with 10 × 10s warmup and 5 × 10s measurement, alternating version order. Profiling was separate. All 120 forks completed without allocation stalls; one warmup trend was inspected and documented. Original server settings were restored.

Validation: 6,029 Spock cases passed (7 existing skips), all ten generator/fixture outputs match baseline, build/TCK checks passed, and the local per-class coverage gate reports no regressions. Local counts include two pre-existing parser tests excluded from this PR. CI also passed Java 17/21/25, jcstress, Javadoc, and the per-class coverage gate.

Full results, raw JMH samples, profile evidence, caveats, and reproduction instructions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xuorig reacted with heart emoji
All reactions
  • ❤️ 1 reaction
andimarek added 5 commits November 3, 2026 18:53
@andimarek
Benchmark both schema generators across all five large schemas
ca944d6
@andimarek
Build traversal breadcrumb lists only when requested
86c4cf2
@andimarek
Allocate traversal context variables only when first written
d124421
@andimarek
Reduce schema child copying and unnecessary validation lookups
f32f89b
@andimarek
Document schema generation benchmarks and reproducible performance ev…
9714171
…idence
@github-actions

github-actions Bot commented Nov 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Test Report

Test Results

Java Version Total Passed Failed Errors Skipped
Java 17 6310 (+48 🟢) 6254 (+48 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 21 6310 (+48 🟢) 6254 (+48 🟢) 0 (±0) 0 (±0) 56 (±0)
Java 25 6310 (+48 🟢) 6254 (+48 🟢) 0 (±0) 0 (±0) 56 (±0)
jcstress 32 (±0) 32 (±0) 0 (±0) 0 (±0) 0 (±0)
Total 18962 (+144 🟢) 18794 (+144 🟢) 0 (±0) 0 (±0) 168 (±0)

Code Coverage (Java 25)

Metric Covered Missed Coverage vs Master
Lines 30380 3070 90.8% ±0.0%
Branches 9022 1494 85.8% +0.1% 🟢
Methods 8107 1181 87.3% +0.1% 🟢

Changed Class Coverage (11 classes)

Class Line Branch Method
g.s.GraphQLDirectiveContainer +25.0% 🟢 ±0.0% +25.0% 🟢
g.s.i.e.BaseError +11.1% 🟢 +25.0% 🟢 +16.7% 🟢
g.s.i.ImplementingTypesChecker +0.9% 🟢 +1.1% 🟢 ±0.0%
g.s.i.SchemaGeneratorAppliedDirectiveHelper ±0.0% +2.0% 🟢 ±0.0%
g.s.i.SchemaGeneratorHelper ±0.0% +1.6% 🟢 ±0.0%
g.s.i.SchemaGeneratorHelper
$BuildContext
+4.2% 🟢 ±0.0% +5.3% 🟢
g.s.i.SchemaTypeChecker ±0.0% +1.2% 🟢 ±0.0%
g.s.i.TypeUtil +5.3% 🟢 +25.0% 🟢 +14.3% 🟢
g.s.SchemaElementChildrenContainer +12.1% 🟢 +15.0% 🟢 +10.0% 🟢
g.s.v.AppliedDirectivesAreValid +4.3% 🟢 +10.0% 🟢 ±0.0%
g.u.DefaultTraverserContext +1.6% 🟢 +3.3% 🟢 +3.3% 🟢

Full HTML report: build artifact jacoco-html-report

Updated: 2026-11-06 09:20:38 UTC

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bbakerman
bbakerman approved these changes Nov 4, 2026
View reviewed changes
andimarek added 5 commits November 6, 2026 07:02
@andimarek
Merge remote-tracking branch 'origin/master' into codex/large-schema-…
baf5395
…generation-performance
@andimarek
Reduce allocation and repeated work in SDL validation
8117620
@andimarek
Reduce directive construction allocation during schema generation
ffc2628
@andimarek
Remove obsolete directive storage and cover malformed interface defin…
8025109
…itions
@andimarek
Document direct SDL performance experiments and final comparison
608095d
@andimarek andimarek changed the title Reduce allocation and traversal work during schema generation Reduce SDL checking, directive construction, and schema traversal work Nov 6, 2026
@andimarek

andimarek commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

@xuorig could you give this a go before merging and see if this improves things for you?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xuorig

xuorig commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Hi @andimarek sorry I had missed this thread. I'll give this a try tomorrow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@bbakerman bbakerman bbakerman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@andimarek @xuorig @bbakerman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.