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

refactor: Improve parse performance #25

Merged
merged 27 commits into from
Apr 2, 2024
Merged

refactor: Improve parse performance #25

merged 27 commits into from
Apr 2, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Apr 1, 2024

Set of changes

  • Refactor approach to value() parsing to combine all matches into single regex
    • Collapse object and list parsing into the value() parser
  • Refactor multiple loop conditions (in arguments(), variableDefinitions()) to assume items or empty result
  • Avoid returning empty directives, arguments, and variableDefinitions arrays to avoid redundant allocations
  • Squash away typeCondition() and name() helpers
  • Collapse selectionSet() parser to combine fragment and field parsers into one loop
  • Remove some redundant ignore() calls

Note: The benchmarks fluctuate. Sometimes the new code will reach >150K Hz, sometimes it won't.

Before

@0no-co/graphql.web  111,997.84  0.0075  0.8377  0.0089  0.0083  0.0334  0.0338  0.0581  ±0.55%    56000

After

@0no-co/graphql.web  150,803.82  0.0058  0.6025  0.0066  0.0065  0.0087  0.0096  0.0651  ±0.38%    75404   fastest

This now consistently beats graphql parsing performance in our benchmarks.

Copy link

changeset-bot bot commented Apr 1, 2024

🦋 Changeset detected

Latest commit: d06f4a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@0no-co/graphql.web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kitten kitten requested a review from JoviDeCroock April 1, 2024 23:10
@kitten kitten merged commit 6e4df56 into main Apr 2, 2024
2 checks passed
@kitten kitten deleted the refactor/parser-perf branch April 2, 2024 10:35
@github-actions github-actions bot mentioned this pull request Apr 2, 2024
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.

2 participants