Skip to content
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

Merged
merged 10 commits into from Jul 26, 2022

Conversation

bbakerman
Copy link
Member

@bbakerman bbakerman commented Mar 22, 2022

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 chained InstrumentationContext object (list of all the other InstrumentationContext objects) which gets held in memory for a long time and is not eligible for GC.

This PR starts to change Instrumentation so that

  1. The InstrumentationState is passed into each method direct (no need for new objects to be allocated)
  2. The returned InstrumentationContext can be null and hence no object allocation is needed here either

All 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 empty InstrumentationContext case - why? Because there is no object allocation involved in the some case versus the empty case.

  • The instrumentXXX methods have been changed to take in InstrumentationState for consistency reasons with all the others even if the memory pressure problem doesnt apply to them as much

  • The instrumentXXX methods MUST return a non null object as before - I put @Nonnull annotations to this better

The 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

…licitly-to-instrumentation

# Conflicts:
#	src/main/java/graphql/execution/instrumentation/ChainedInstrumentation.java
@bbakerman bbakerman changed the title WIp - State is passed explicitly to instrumentation State is passed explicitly to instrumentation and parameters are NOT mutated Apr 29, 2022
@jonclarkethg
Copy link

Hi. Wondering if there is an update on this as we're very keen to see the impact on object allocation. Thanks :)

@bbakerman
Copy link
Member Author

I am waiting on a final review from @andimarek - Andi?

@jonclarkethg
Copy link

@andimarek did you get a chance to review this PR?

@Aynemayne
Copy link

Hello @andimarek and/or @bbakerman! Did you manage to follow up on this PR?
Thanks in advance!

…licitly-to-instrumentation

# Conflicts:
#	src/main/java/graphql/execution/Execution.java
@bbakerman
Copy link
Member Author

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

Comment on lines +75 to +79
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");
}

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.

Copy link
Member

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

josephlbarnett added a commit to josephlbarnett/graphql-kotlin that referenced this pull request Jul 27, 2022
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769
josephlbarnett added a commit to josephlbarnett/graphql-kotlin that referenced this pull request Jul 28, 2022
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769

ValidationError string changed slightly so adjust assertions.
josephlbarnett added a commit to josephlbarnett/graphql-kotlin that referenced this pull request Jul 28, 2022
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769

ValidationError string changed slightly so adjust assertions.
samuelAndalon pushed a commit to ExpediaGroup/graphql-kotlin that referenced this pull request Jul 28, 2022
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769

ValidationError string changed slightly so adjust assertions.
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769

ValidationError string changed slightly so adjust assertions.
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.

None yet

5 participants