New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State is passed explicitly to instrumentation and parameters are NOT mutated #2769
State is passed explicitly to instrumentation and parameters are NOT mutated #2769
Conversation
…passing in state to the instrumentation fields
…licitly-to-instrumentation
…licitly-to-instrumentation # Conflicts: # src/main/java/graphql/execution/instrumentation/ChainedInstrumentation.java
…licitly-to-instrumentation
Hi. Wondering if there is an update on this as we're very keen to see the impact on object allocation. Thanks :) |
I am waiting on a final review from @andimarek - Andi? |
@andimarek did you get a chance to review this PR? |
Hello @andimarek and/or @bbakerman! Did you manage to follow up on this PR? |
…licitly-to-instrumentation # Conflicts: # src/main/java/graphql/execution/Execution.java
I just fixed up the merge conflict on this PR - this will be merged into 19.0 - 19.0 is to be released very soon - probably next week |
public InstrumentationContext<ExecutionResult> beginExecution(InstrumentationExecutionParameters parameters) { | ||
// these assert methods have been left in so that we truly never call these methods, either in production nor in tests | ||
// later when the deprecated methods are removed, this will disappear. | ||
return Assert.assertShouldNeverHappen("The deprecated " + "beginExecution" + " was called"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this is a breaking change for eg, a downstream ExecutionStrategy implementation that calls beginExecution(parameters)
and needs to be changed to call beginExecution(parameters, parametersInstrumentationState)
. May want to update the 19.0 release notes which claim no breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot @josephlbarnett ... will update the release notes
FlowSubscriptionExecutionStrategy needs to be updated to pass instrumentationState to instrumentations per graphql-java/graphql-java#2769
FlowSubscriptionExecutionStrategy needs to be updated to pass instrumentationState to instrumentations per graphql-java/graphql-java#2769 ValidationError string changed slightly so adjust assertions.
FlowSubscriptionExecutionStrategy needs to be updated to pass instrumentationState to instrumentations per graphql-java/graphql-java#2769 ValidationError string changed slightly so adjust assertions.
FlowSubscriptionExecutionStrategy needs to be updated to pass instrumentationState to instrumentations per graphql-java/graphql-java#2769 ValidationError string changed slightly so adjust assertions.
FlowSubscriptionExecutionStrategy needs to be updated to pass instrumentationState to instrumentations per graphql-java/graphql-java#2769 ValidationError string changed slightly so adjust assertions.
As per #2743 - object allocation at scale can be problematic because in a chained instrumentation call we create new
instrumentation parameters
per chained call and we create a chainedInstrumentationContext
object (list of all the otherInstrumentationContext
objects) which gets held in memory for a long time and is not eligible for GC.This PR starts to change
Instrumentation
so thatInstrumentationState
is passed into each method direct (no need for new objects to be allocated)InstrumentationContext
can be null and hence no object allocation is needed here eitherAll the places that received a
InstrumentationContext
have been changed to swap in a static NooP object (singleton) and hence they dont change a lot in a consuming sense.This PR as is shows that ALL the tests pass - that is the new methods are delegated back to the old no problems.
Some important decisions I made
I used
null
and not Optional for the emptyInstrumentationContext
case - why? Because there is no object allocation involved in thesome
case versus the empty case.The
instrumentXXX
methods have been changed to take inInstrumentationState
for consistency reasons with all the others even if the memory pressure problem doesnt apply to them as muchThe
instrumentXXX
methods MUST return a non null object as before - I put@Nonnull
annotations to this betterThe ChainedInstrumentation class has been updated to copy with null contexts being returned returned AND it only uses the new methods with state and never the old.
Still TODO
I have not updated ALL the provided instrumentations to take advantage of the new methods. I think this is best dont in a another PR to reduce the scope of this already large PR. They all work unchanged so lets not make it more complicated than it needs to be and we can improve it via another PR