maticzav / graphql-middleware

Split up your GraphQL resolvers in middleware functions
MIT License
1.15k stars 58 forks source link

Remove uses of reduce/spread which causes significant latency to large middlewares #567

Closed ryanquinn3 closed 1 year ago

ryanquinn3 commented 1 year ago

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.

ryanquinn3 commented 1 year ago

Hey @dimatill, any chance you've had a moment to look over this change?

dimatill commented 1 year ago

wow, @ryanquinn3 this is a great finding! Thank you!

ryanquinn3 commented 1 year ago

@dimatill This is what I get for submitting the PR via github's web editor 😞

Commit pushed. I've confirmed that the package builds & tests pass.

dimatill commented 1 year ago

Thank you @ryanquinn3 !!!

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 6.1.35 :tada:

The release is available on:

Your semantic-release bot :package::rocket: