Skip to content

Avoid no-op field fetch adapter allocation#4375

Open
nwjsmith wants to merge 1 commit into
graphql-java:masterfrom
nwjsmith:push-rvxtymoulwyn
Open

Avoid no-op field fetch adapter allocation#4375
nwjsmith wants to merge 1 commit into
graphql-java:masterfrom
nwjsmith:push-rvxtymoulwyn

Conversation

@nwjsmith
Copy link
Copy Markdown

@nwjsmith nwjsmith commented May 8, 2026

Problem

beginFieldFetching keeps older beginFieldFetch implementations working by
calling the deprecated method and adapting the returned InstrumentationContext.
For instrumentations that inherit the default/no-op beginFieldFetch, that means
adapting SimpleInstrumentationContext.noOp() into a new anonymous
FieldFetchingInstrumentationContext.

That adapter allocation happens once per field fetch. In a ChainedInstrumentation
with multiple legacy/no-op field-fetch instrumentations, each instrumentation can
pay that allocation for every field even though all callbacks are no-ops.

Fix

When the legacy hook returns the canonical SimpleInstrumentationContext.noOp()
instance, return the canonical FieldFetchingInstrumentationContext.NOOP directly
instead of allocating an adapter.

Real legacy beginFieldFetch overrides are still adapted normally, and
instrumentations that override beginFieldFetching themselves are unaffected.

Tests

Added coverage for:

  • default Instrumentation no-op field fetching
  • SimplePerformantInstrumentation inherited no-op field fetching
  • deprecated overrides that explicitly return noOp()
  • deprecated overrides that return a real context and still need adaptation

Validated with:

./gradlew test --tests graphql.execution.instrumentation.InstrumentationDefaultMethodsTest --no-build-cache

@nwjsmith nwjsmith marked this pull request as ready for review May 8, 2026 18:26
The default field-fetching bridge still has to support legacy
beginFieldFetch implementations, but the inherited no-op path should not
allocate a per-field adapter. Return the canonical field-fetching no-op
when the legacy hook returns the canonical no-op context, while still
adapting real legacy contexts.
@nwjsmith nwjsmith force-pushed the push-rvxtymoulwyn branch from 2bc5bf5 to 58a802d Compare May 8, 2026 18:29
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