Avoid no-op field fetch adapter allocation#4375
Open
nwjsmith wants to merge 1 commit into
Open
Conversation
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.
2bc5bf5 to
58a802d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
beginFieldFetchingkeeps olderbeginFieldFetchimplementations working bycalling the deprecated method and adapting the returned
InstrumentationContext.For instrumentations that inherit the default/no-op
beginFieldFetch, that meansadapting
SimpleInstrumentationContext.noOp()into a new anonymousFieldFetchingInstrumentationContext.That adapter allocation happens once per field fetch. In a
ChainedInstrumentationwith 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.NOOPdirectlyinstead of allocating an adapter.
Real legacy
beginFieldFetchoverrides are still adapted normally, andinstrumentations that override
beginFieldFetchingthemselves are unaffected.Tests
Added coverage for:
Instrumentationno-op field fetchingSimplePerformantInstrumentationinherited no-op field fetchingnoOp()Validated with:
./gradlew test --tests graphql.execution.instrumentation.InstrumentationDefaultMethodsTest --no-build-cache