Skip to content

avoid wrapping materialized fieldValueObject in a CompletableFuture #3943

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

Conversation

samuelAndalon
Copy link

@samuelAndalon samuelAndalon commented Apr 29, 2025

While updating graphql-kotlin to graphql-java 23 found that completeField is still wrapping FieldValueInfo.fieldValueObject in a CompletableFuture for objects already materialized / in memory

this might be considered a follow up of the Completable Future wrapping change set that came in graphql-java 22
https://github.com/graphql-java/graphql-java/releases/tag/v22.0

I don't think this is a breaking change.

@samuelAndalon samuelAndalon changed the title avoid wrapping materialized fieldValueObject in a completable future avoid wrapping materialized fieldValueObject in a CompletableFuture Apr 29, 2025
ctxCompleteField.onDispatched();
executionResultFuture.whenComplete(ctxCompleteField::onCompleted);
if (fieldValueInfo.isFutureValue()) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've done this as well but it has the unchecked cast already handled internally by FieldValueInfo

 Object executionResult = fieldValueInfo.getFieldValueObject();
 ctxCompleteField.onDispatched();
  if (executionResult instanceof CompletableFuture) {
   @SuppressWarnings("unchecked")
    CompletableFuture<Object> executionResultFuture = (CompletableFuture<Object>) executionResult;
    executionResultFuture.whenComplete(ctxCompleteField::onCompleted);
 } else {
     ctxCompleteField.onCompleted(executionResult, null);
 }

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch - I am embarrassed I missed this in the great "materialised migration" effort

@bbakerman bbakerman added the performance work that is primarily targeted as performance improvements label Apr 29, 2025
@samuelAndalon
Copy link
Author

all good! thank you, now I am curious the memory and CPU improvement this change will bring

@bbakerman bbakerman merged commit ea9104d into graphql-java:master Apr 30, 2025
1 of 2 checks passed
@samuelAndalon samuelAndalon deleted the avoid-wrapping-fvi-completable-future branch April 30, 2025 16:34
@samuelAndalon
Copy link
Author

@bbakerman I wonder if this can be cherry picked to version 22.x ? I can prepare the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance work that is primarily targeted as performance improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants