Title: Reuse collected sub fields for objects of the same type by Meemaw · Pull Request #4501 · graphql-java/graphql-java · GitHub
Open Graph Title: Reuse collected sub fields for objects of the same type by Meemaw · Pull Request #4501 · graphql-java/graphql-java
X Title: Reuse collected sub fields for objects of the same type by Meemaw · Pull Request #4501 · graphql-java/graphql-java
Description: Problem ExecutionStrategy.completeValueForObject runs FieldCollector.collectFields for every object in the result. For a list of N objects this repeats the same work N times: walking the selection set, evaluating @skip/@include, expanding fragments and building a fresh LinkedHashMap + MergedFields + MergedSelectionSet. The result only depends on the merged field, the resolved object type, the variables and the fragments, and the last two are fixed for an execution. Async-profiler on ExecutionBenchmark showed field collection at ~16% of CPU and ~20% of allocated bytes. Change The collected sub fields are memoized per execution in ExecutionContext, keyed by MergedField and then by the resolved GraphQLObjectType. Every object of the same type under the same field reuses the same immutable MergedSelectionSet. Sub fields are shared too, so cache hits cascade down the tree. Key correctness: MergedField.equals compares the class and the AST Field nodes (Field uses identity), so two merged fields are only equal when they come from exactly the same set of AST fields. Interface/union results are keyed per concrete object type. Fallback to the old per-object collection when: incremental support (@defer) is enabled, because DeferredExecution instances are created per collection, or a custom ConditionalNodeDecision is in the GraphQLContext, because the callback is not guaranteed to be deterministic. Memory: the cache is bounded by the number of distinct (field, object type) pairs in the operation and lives only as long as the ExecutionContext. API surface: this adds a field to ExecutionContext plus one @Internal getter, getCollectedSubFields(). Happy to move it elsewhere if you prefer. Benchmarks Apple Silicon, JDK 21. Base vs this branch jars were run interleaved (alternating, 3 rounds × 2 forks each = 6 forks per side) to cancel out machine drift. Δ shows the 95% confidence interval. Benchmark Throughput Δ Allocated bytes/op ExecutionBenchmark.benchmarkThroughput +14.7% ± 7.0% 1,073,041 → 903,689 (−15.8%) SimpleQueryBenchmark.benchMarkSimpleQueriesThroughput +10.2% ± 9.8% 1,933,273 → 1,510,351 (−21.9%) IntrospectionBenchmark (large-schema-2) +19.4% ± 9.0% 112.3M → 98.2M (−12.6%)¹ An earlier run on a quieter machine of the same change (before a cosmetic computeIfAbsent refactor) gave tighter intervals: ExecutionBenchmark +9.3% ± 0.8%, SimpleQuery +15.0% ± 1.1%, Introspection +18.4% ± 8.1%. An A/A run (base vs base) on that machine showed no significant difference, with a noise floor of about ±1.8% on ExecutionBenchmark. ¹ Introspection bytes/op vary between forks even for the same jar (96.9M vs 114.5M observed for base), so treat that row as indicative only. Tests New CollectedSubFieldsReuseTest covers: objects of different concrete types in the same interface list each get their own type's fields aliased fields with different sub selections are collected separately fields merged across fragments keep all their sub selections collection happens once per (field, object type) a non-deterministic ConditionalNodeDecision is still asked for every object, so the cache is bypassed the cache is bypassed when incremental support is enabled To check the tests guard the fallbacks, I temporarily removed the bypass condition: the ConditionalNodeDecision test then returned wrong data and the incremental test failed. The full test suite passes, apart from the 14 locale-dependent StringValueParsingUnicodeTest failures that also occur on master with a non-English JVM locale (fixed separately in #4500). 🤖 Generated with Claude Code
Open Graph Description: Problem ExecutionStrategy.completeValueForObject runs FieldCollector.collectFields for every object in the result. For a list of N objects this repeats the same work N times: walking the selection ...
X Description: Problem ExecutionStrategy.completeValueForObject runs FieldCollector.collectFields for every object in the result. For a list of N objects this repeats the same work N times: walking the selection ...
Opengraph URL: https://github.com/graphql-java/graphql-java/pull/4501
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c58aa57d-da4e-ca2f-6ef9-9c94f78e223b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BCE4:1AE20C:23ADB46:2D234BF:6B017C6C |
| html-safe-nonce | f51b9578ac0d5b7891aef7accef9be0dae6b61fc32f69cf9ba8570c5d4fc77b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0U0OjFBRTIwQzoyM0FEQjQ2OjJEMjM0QkY6NkIwMTdDNkMiLCJ2aXNpdG9yX2lkIjoiODU5Mzg4ODAzMzg4MTgxNjE3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4ba8e42a12ac75d1f537e2adf1ebc5e7a7eb0713f69c717cea5f2cc3f73f0c8f |
| hovercard-subject-tag | pull_request:4909314017 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/graphql-java/graphql-java/pull/4501/files |
| twitter:image | https://avatars.githubusercontent.com/u/8524109?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8524109?s=400&v=4 |
| og:image:alt | Problem ExecutionStrategy.completeValueForObject runs FieldCollector.collectFields for every object in the result. For a list of N objects this repeats the same work N times: walking the selection ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/graphql-java/graphql-java git https://github.com/graphql-java/graphql-java.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 38602457 |
| octolytics-dimension-repository_nwo | graphql-java/graphql-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38602457 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/graphql-java |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width