GraphQL-Ruby 2.6 has a new, faster execution system
Hey everyone,
GraphQL-Ruby v2.6 is hot off the presses and I’m most excited to announce a new runtime engine, GraphQL::Execution::Next. This new module follows a long line of attempts to reduce GraphQL-Ruby’s query execution overhead. It closely follows Shopify’s work on breadth-first execution via @gmac's proof-of-concept, graphql-breadth-exec
Performance
The new runtime engine really shines when producing responses with nested lists, for example:
{
posts(first: 10) { # 10 posts
comments(first: 10) { # 100 comments
replies(first: 10) { ... } # 1000 replies
}
}
}
In an isolated benchmark like that, Execution::Next has about 90% less latency overhead and uses about 49% less memory. It won't make your database queries faster ... but if you've already tuned your I/O and application logic, you'll probably see a very significant speed-up.
Under the hood, it works in batches: first posts, then comments, then replies. This greatly reduces the number of calls to field resolution and the amount of book-keeping data required during execution. You can read more background on the algorithm in the docs.
Compatibility
Maintaining compatibility was a very high priority for me. I compiled a migration guide including feature-by-feature compatibility notes and wrote an auto-migration tool based on my own migration work.
If you take Execution::Next for a spin and encounter compatibility challenges, please open an issue on GitHub so we can explore migration strategies. I'm really hoping to make the process as smooth as possible for existing GraphQL schemas!
GraphQL-Pro v1.30.0 and GraphQL-Enterprise v1.7.0 are ready for Execution::Next. GraphQL-Batch has been updated on main but hasn't been released yet. If you maintain a gem that integrates with GraphQL-Ruby, feel free to get in touch via GitHub about supporting this new runtime.
In other news ...
I have also been improving DetailedTrace, the plugin for storing and viewing detailed GraphQL traces on a sample of production traffic. It now supports an ActiveRecord-based backend and properly handles a wider variety of classes and objects when inspecting results.
As always, you'll find lots other big fixes and minor features in the CHANGELOG, the Pro CHANGELOG, and the Enterprise CHANGELOG.
Check out the new runtime and let me know what you think!
Best,
Robert