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

polish(fragmentArgs): simplify fragment args execution #4182

Closed

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Sep 8, 2024

...by creating a map for each fragment with fragment variables with the combined local and global variables

background: this was in the original version PR #4015, was taken out -- by me -- when i misunderstood and thought that when a fragment variable shadows an operation variable, the operation variable could still leak through if the fragment variable had no default, and I thought it was necessary within getArgumentValues to still have the signatures. that was fixed, but the original method of coalescing local and global variables within a map was not restored, in favor of just retaining both maps

advantage to the original approach, which this PR restores => does not change the signature of getVariableValues, getDirectiveValues, valueFromAST. the lazy method retains both maps and requires passing the local fragment variables to those functions

disadvantage to the original approach => creating a combined variable map of local and global variables may be a waste if the global variables are not actually used in that fragment

I am not sure which way is better! Just raising this for discussion.

@yaacovCR yaacovCR requested a review from a team as a code owner September 8, 2024 18:11
Copy link

github-actions bot commented Sep 8, 2024

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

Copy link

netlify bot commented Sep 8, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit c523396
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66df59aa3396fa00088df951
😎 Deploy Preview https://deploy-preview-4182--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yaacovCR yaacovCR marked this pull request as draft September 8, 2024 18:43
@yaacovCR yaacovCR closed this Sep 8, 2024
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Sep 8, 2024

Closing for now as I think I like what we have currently better, but anyone can feel free to chime in and we can reopen as necessary.

@yaacovCR yaacovCR reopened this Sep 9, 2024
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Sep 9, 2024

Reopening as I got some positive feedback offline for this approach. This also helps with a bug I believe I noticed, in that we did not remember to pass fragmentVariables to parseLiteral for scalars, have to investigate further, but this PR could be a solution as well.

@yaacovCR yaacovCR marked this pull request as ready for review September 9, 2024 10:35
by creating a map for each fragment with fragment variables with the properly combined local and global variables

background: this was in the original PR graphql#4015, was taken out by me when i misunderstood and thought that when a fragment variable shadows an operation variable, the operation variable could still leak through if the fragment variable had no default, and I thought it was necessary within getArgumentValues to still have the signatures

advantages to the original approach, which this PR restores: does not change the signature of getVariableValues, getDirectiveValues, valueFromAST

disadvantages:
creating a combined variable map of local and global variables may be a waste if the global variables are not actually used in that fragment
@yaacovCR yaacovCR force-pushed the simplify-fragment-args-execution branch from aaaf061 to 884f67c Compare September 9, 2024 10:51
@yaacovCR yaacovCR added the PR: polish 💅 PR doesn't change public API or any observed behaviour label Sep 9, 2024
@yaacovCR
Copy link
Contributor Author

yaacovCR commented Sep 9, 2024

So with this new approach of coalescing the fragmentVariableValues and operationVariableValues, we will have to perform a copy operation for each fragment spread with arguments, for each operation variable value, for a total of FragmentSpreadWithArguments * OperationVariableValues copy operations.

With the existing approach, we have to perform an additional check * the number of VariableUsages.

As the number of fragment spreads with arguments and operation variable values increases, the existing approach is faster.

I added a benchmark with a 100 of each, and I get the following:

image

-- This PR gives about a 20% speed drop, and a 25% memory increase.

When resetting the benchmark to 20 of each, I get the following:

image

-- This PR gives about a 6% speed drop, and an 8% memory increase.

When setting to 1 of each, I get:

image

-- This PR gives a 2% speed increase and a less than 1% memory increase.

I think these results basically work with the big O analysis above => and to me they suggest we stick with the original version, but, of course, the speed/memory tradeoffs have to be balanced against the overall change to the API. It might make sense to keep this PR in the experimental stage and then re-optimize later.

@yaacovCR
Copy link
Contributor Author

Closing for now, nice to have this as a foil/strawman.

@yaacovCR yaacovCR closed this Sep 15, 2024
@yaacovCR yaacovCR deleted the simplify-fragment-args-execution branch September 25, 2024 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: polish 💅 PR doesn't change public API or any observed behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants