question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance degradation after applying graphql-shield

See original GitHub issue

Bug 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:closed
  • Created 4 years ago
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
jaywhy13commented, Jul 4, 2019

@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 by 10s then returns (my attempt at poor man’s request queueing).

I used vegeta to do some load testing. When I tried doing 350req/s for 1m 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 the 10s. Then I changed the resolver to return after 3s 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… image

To without Shield… image

Hope this helps!

1reaction
maticzavcommented, Jul 5, 2019

Thank you both for such profound insights on the performance. I am away for a vacation and will return on Tuesday.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found