Remove uses of reduce/spread which causes significant latency to large middlewares #567
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.
Hi there, at work we have a very large graphql schema and use graphql middlewares heavily. I've recently been debugging why our graphql server takes so long to start up and identified one area in this library that contributes a good chunk of that time.
I found that this library performs quite poorly when a particular middleware contains a lot (~1k+) of keys. After a deeper inspection, I see that applicator.ts uses the reduce/spread anti-pattern which I have been bitten by a few times in the last handful of years. The simple changes in this PR should not change the behavior of this library at all but they did reduce the total latency of our
applyMiddleware
call from ~11s to about 6s. If others in the community are using this library with large schemas & middlewares then I want them to benefit as well.