Performance degradation after applying graphql-shield
See original GitHub issueBug report
- I have checked other issues to make sure this is not a duplicate.
Describe the bug
Querying multiple fields for hundreds of rows becomes noticeably slower after applying graphql-shield
middleware.
To Reproduce
I’ve created repository reproducing this issue: https://github.com/lynxtaa/graphql-shield-performance
- Without
graphlql-shield
it takes 30-40ms to query all users. - With
graphql-shield
it takes ~260ms.
Notice that I’m not applying any rules for type User
.
Is there a way to improve performance for large queries?
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (4 by maintainers)
Top Results From Across the Web
Performance degradation after applying graphql-shield #416
Querying multiple fields for hundreds of rows becomes noticeably slower after applying graphql-shield middleware. To Reproduce. I've created ...
Read more >Security and performance tips and tricks for your GraphQL ...
This post shows you how to use introspection, authorization, and other queries to improve security and performance in your GraphQL apps.
Read more >Securing a federated graph - Apollo GraphQL Docs
One of the easiest things to do is to guard against deeply nested queries such as this one is to set a maximum...
Read more >GraphQL Shield - Medium
GraphQL Shield manages permission layer intelligently and has an intuitive API. The process of implementing Shield into existing applications ...
Read more >GraphQL Performance issues and how to handle them
One of biggest GraphQL flaws is missing of some basic implementation know from which are crucial for application performance.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maticzav @lynxtaa I tried to do a bit more experimenting with profiling and looking at the garbage collection patterns. I’m no expert in either of these topics but I’m hoping what I found helps. I added a repo here to do the testing.
I setup a GraphQL server running on Express with a basic GraphQL schema that returns a list of
Movies
with 8 attributes. For the tests I randomly generated 100 movies to be returned in the GQL query. I used a resolver that pauses by10s
then returns (my attempt at poor man’s request queueing).I used
vegeta
to do some load testing. When I tried doing350req/s
for1m
I noticed that when Shield was applied, there was twice as much garbage collection as when Shield middleware wasn’t there. I showed the results in the README of the project. Also, it would run out of memory ever so often when Shield was applied.Finally, I used the
v8-profiler-next
to profile the system under load. I looked at the profiles in Chrome’s Javascript Profiler but not too much jumped out at me.This profile shows running
350req/s
with the10s
. Then I changed the resolver to return after3s
and recorded the results with Shield and without Shield. One caveat is that I had to stop the load testing early for Shield so that the NodeJS process didn’t quit on me. I needed to save the profile.From the little I gleaned from the profiles, it confirms that the garbage collection takes longer. Compare with Shield…
To without Shield…
Hope this helps!
Thank you both for such profound insights on the performance. I am away for a vacation and will return on Tuesday.