-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(gatsby): cache parsing and validation results in graphql-runner #20477
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think it's good to merge after some testing.
I tried it on several sites and it seems to be working OK. The biggest impact noticed for https://github.com/tsriram/ifsc/ (after our other recent tweaks): Run queries step: Which is almost 60%+ speedup (for this specific step) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 🙌🏼
Hello, Im not sure how to explain this but since upgrading Gatsby to v2.18.25, I've noticed that when i scroll down to the bottom of the page, there is like a 1px line at the very bottom. You can reproduce this on the gatsbyjs.org website if you scroll to the bottom of the page and change the background color of the footer to a dark color inside dev tools. |
@t2ca Could you file a new issue about this, please? If you think your issue is related to this PR please link it. To me it sounds like a completely different issue. |
Description
This PR introduces a cache for GraphQL parsing and validation steps in the
graphql-runner
, whichimproves the performance of query running for about 18% on our synthetic
benchmarks/query
site.It is inspired by an experiment of @pieh with
graphql-jit
. We saw positive numbers from thegraphql-jit
branch, but it turns out most benefits came from avoiding re-parsing and re-validatingthe same query.
Here are some numbers on my laptop (queries per second, higher is better):
Node 10.17.0:
Node 13.1.0 (surprisingly slower in general in this benchmark):
For each test, I ran the build 7 times using
NUM_PAGES=20000 gatsby build
, ignored the first tworesults (warm-up), and averaged the remaining 5. The number in the table is from the "run queries"
steps (queries per second).
Typical scenario
Say you have 1000 pages with the same template component. Then the
graphql-runner
executesGraphQL query of this template 1000 times (with different variables).
But GraphQL query execution involves 3 steps:
Those steps occur inside the
graphql
function call (which is a facade for those steps).Before this PR
graphql-runner
was using thisgraphql
facade and for the example aboveit would have run each step 1000 times (for the same query).
In this PR it runs
parsing
andvalidation
only once per query and still runsexecute
1000 times (with different variables/context).
In general, it should improve the performance of sites executing the same query
many times during the build.
Thoughts about graphql-jit
Without cache,
graphql-jit
has additional overhead for query compilation. But it performs greatwhen the query is cached.
In the real-world projects though execution time itself is small comparing to GraphQL resolvers
time (which we see even in this benchmark) but we can get back to
graphql-jit
when we needto squeeze the last millisecond from query running.
The project is also in a too early stage, but we should definitely keep an eye on it
(it is very promising).