feat(rate-limiter): improve performance#2676
Merged
EmrysMyrddin merged 5 commits intomainfrom Sep 15, 2025
Merged
Conversation
Contributor
🚀 Snapshot Release (
|
| Package | Version | Info |
|---|---|---|
@envelop/parser-cache |
9.0.1-alpha-20250912150608-74bc2fbef267d299dfb47a06509f8d305c4b3160 |
npm ↗︎ unpkg ↗︎ |
@envelop/rate-limiter |
8.1.0-alpha-20250912150608-74bc2fbef267d299dfb47a06509f8d305c4b3160 |
npm ↗︎ unpkg ↗︎ |
@envelop/response-cache |
8.0.2-alpha-20250912150608-74bc2fbef267d299dfb47a06509f8d305c4b3160 |
npm ↗︎ unpkg ↗︎ |
@envelop/validation-cache |
9.0.1-alpha-20250912150608-74bc2fbef267d299dfb47a06509f8d305c4b3160 |
npm ↗︎ unpkg ↗︎ |
Contributor
💻 Website PreviewThe latest changes are available as preview in: https://784b91a1.envelop.pages.dev |
d89a326 to
12bf1a1
Compare
c8aa42f to
911e296
Compare
89bdd49 to
74bc2fb
Compare
ardatan
approved these changes
Sep 12, 2025
Member
ardatan
left a comment
There was a problem hiding this comment.
You can also use mapSchema but this is also good
Contributor
Author
|
Yes, that was my first thought, and then I found out that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
To apply the configuration based on type and field name, the rate limiter plugin is using
minimatchto allow glob patterns and simplify the configuration.But
minimatchimplementation is very unefficient. It usesRegExpunder the hood (which is already pretty expensive), but it doesn't even memoize theRegExpinstances. This means that a new one is created and compiled for each resolver, for each configured type/field.Having such heavy process in a hot path like this one can have a big impact of performance.
This PR replaces
minimatchbypicomatchand builds all relevant matchers ahead of time. This way, only the actual string test is done in the hot path.It also moves all the logic for replacing the resolver based on configuration to the
onSchemaChangehook, to minimize the overhead at execution time.Realted to graphql-hive/gateway#1485
Type of change
Please delete options that are not relevant.
Further comments
By reworking the plugin, I also came across some small issues:
directiveNameoption was not honored.