GraphQL-Ruby Newsletter logo

GraphQL-Ruby Newsletter

Subscribe
Archives
August 6, 2023

Performance improvements in GraphQL-Ruby 2.0.x

Hi Everyone,

This year, I've been working with folks at Shopify to improve the performance of query execution in GraphQL-Ruby. I made lots of little changes to speed up hotspots, reduce allocations, use better data structures, and improve compatibility with Ruby's new object shape optimizations. An isolated benchmark suggests that, compared to GraphQL-Ruby v2.0.16, GraphQL-Ruby v2.0.25, reduces GraphQL time and memory overhead for queries by more than 50%. (But, this is just library overhead -- it can't make database queries or application code any faster!)

Besides those, here are some bigger changes that might interest you:
 
- trace_with is a new API for adding custom tracers to GraphQL queries. By using plain-Ruby modules and methods, it can run a lot faster and support distinct "trace modes" to turn specific tracers on and off.
- By default, GraphQL-Ruby assumes that you might be hiding some types or fields from some clients. You can opt out of that visibility system with the new AlwaysVisible plugin.
- The Ruby lexer was completely rewritten to use a StringScanner -- it turned out twice as fast! (Thanks, tenderlove!)
- Also, a new library, graphql/c_parser, provides native implementations of scanning and parsing for GraphQL-Ruby. It's 7-9x faster than the Ruby parser.

You can find details on these changes and more in the GraphQL-Ruby CHANGELOG.

In other news, I've also worked up some improvements for GraphQL-Pro and GraphQL-Enterprise lately:

- Changesets: Types and fields now have added_in: and removed_in: configurations to make changesets easier to trace in source code.
- Redis-backed features now support the new redis-client gem.
- @defer now supports anincremental: true option for the new proposed patch format

I hope you found some of these helpful!

Robert
Don't miss what's next. Subscribe to GraphQL-Ruby Newsletter:
Docs GitHub
This email brought to you by Buttondown, the easiest way to start and grow your newsletter.