Skip to content

OverlappingFieldsCanBeMergedRule: Fix performance degradation#3958

Merged
IvanGoncharov merged 4 commits into
graphql:mainfrom
AaronMoat:fix-performance-degradation
Sep 5, 2023
Merged

OverlappingFieldsCanBeMergedRule: Fix performance degradation#3958
IvanGoncharov merged 4 commits into
graphql:mainfrom
AaronMoat:fix-performance-degradation

Conversation

@AaronMoat

@AaronMoat AaronMoat commented Aug 24, 2023

Copy link
Copy Markdown
Contributor

Update(from @IvanGoncharov): In addition to reversing #3457 this PR improves performance further, see below discussion.

Resolves #3955 (at least greatly mitigates it)

Effectively reverts #3457 which introduces a performance degradation found in #3955. This pull request was identified in a git bisect. The performance issue results in the potential for DOS attacks.

I think there are potential performance increases still available in this file, but this is a simple enough fix for the immediate problem.

The following query:

const maliciousQuery = `{ ${'hello '.repeat(2000)}}`;

now takes 564ms on my machine, and on main takes 12s.

@netlify

netlify Bot commented Aug 24, 2023

Copy link
Copy Markdown

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 2991112
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/64f771eb500b3b00086f752e
😎 Deploy Preview https://deploy-preview-3958--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.

@AaronMoat

Copy link
Copy Markdown
Contributor Author

Hi @graphql/graphql-js-reviewers (I can't seem to ping this list - so @martijnwalraven @Cito @yaacovCR @IvanGoncharov @saihaj) any chance we could get some eyes on this? 🙏

@tadhglewis

tadhglewis commented Aug 28, 2023

Copy link
Copy Markdown

I can create a issue as this can be done in a separate PR but it's somewhat concerning this regression was possible in the first place. Would be great to have some perf tests in place.

@github-actions

Copy link
Copy Markdown

Hi @AaronMoat, 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

@AaronMoat

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

@github-actions run-benchmark

@AaronMoat Please, see benchmark results here: https://github.com/graphql/graphql-js/actions/runs/6011999302/job/16306504508#step:6:1

@graphql graphql deleted a comment from github-actions Bot Aug 30, 2023
@yaacovCR

yaacovCR commented Aug 30, 2023

Copy link
Copy Markdown
Contributor

If I’m interpreting the benchmark results correctly, I am not seeing a performance improvement with this fix…

@AaronMoat

Copy link
Copy Markdown
Contributor Author

I don't think this specific scenario is in the benchmarks.

@yaacovCR

Copy link
Copy Markdown
Contributor

I don't think this specific scenario is in the benchmarks.

I guess what I’m wondering is (1) where the crossover point is, as performance seems better on main with our current tests but worse in your above scenario, and (2) whether the better mitigation is to use the maxTokens option when parsing?

maxTokens?: number | undefined;

That’s just my own 2 cents, would really love @IvanGoncharov take

@AaronMoat

Copy link
Copy Markdown
Contributor Author

The note on maxTokens is an interesting one, noting it's linear. I'd argue this is nonlinear, even with this change.

@IvanGoncharov

Copy link
Copy Markdown
Member

@AaronMoat Can you please add a benchmark to this PR otherwise this problem can reappear in the future.

@AaronMoat

This comment has been minimized.

@github-actions

github-actions Bot commented Sep 1, 2023

Copy link
Copy Markdown

@github-actions run-benchmark

@AaronMoat Something went wrong, please check log.

@AaronMoat

This comment has been minimized.

@github-actions

github-actions Bot commented Sep 2, 2023

Copy link
Copy Markdown

@github-actions run-benchmark

@AaronMoat Something went wrong, please check log.

@AaronMoat

Copy link
Copy Markdown
Contributor Author

Unsure what's going on with the benchmarks; it seems to have not even got up to the new one this time.

@IvanGoncharov

Copy link
Copy Markdown
Member

@AaronMoat Sorry for delay, I spend some time playing with this code and came up with 2991112 it further improves performance:
image

It reduces memory usage by ~40%.

@IvanGoncharov IvanGoncharov added the PR: bug fix 🐞 requires increase of "patch" version number label Sep 5, 2023
@IvanGoncharov

Copy link
Copy Markdown
Member

@AaronMoat If you need this fix in v16, please a create separate PR for:
https://github.com/graphql/graphql-js/tree/16.x.x

@IvanGoncharov IvanGoncharov changed the title Fix performance degradation OverlappingFieldsCanBeMergedRule: Fix performance degradation Sep 5, 2023
@IvanGoncharov IvanGoncharov merged commit f94b511 into graphql:main Sep 5, 2023
@AaronMoat AaronMoat deleted the fix-performance-degradation branch September 5, 2023 22:17
@AaronMoat

Copy link
Copy Markdown
Contributor Author

Thanks @IvanGoncharov for taking that and running with it -- raised #3967 for 16.x.x

IvanGoncharov pushed a commit that referenced this pull request Sep 10, 2023
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 11, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 13, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 16, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 16, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 16, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 17, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 17, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Dec 22, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Dec 22, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Dec 22, 2025
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit to yaacovCR/graphql-js that referenced this pull request Jan 27, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (graphql#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 22, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 23, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 24, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 24, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 24, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
yaacovCR pushed a commit that referenced this pull request Feb 24, 2026
originally related to:

OverlappingFieldsCanBeMergedRule: Fix performance degradation (#3958)

Co-authored-by: AaronMoat <AaronMoat@users.noreply.github.com>
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: bug fix 🐞 requires increase of "patch" version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource exhaustion exploit when parsing queries

4 participants