-
Notifications
You must be signed in to change notification settings - Fork 45
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
improvements to lexer + parser performance #293
Comments
Interesting! This seems to be an issue specific to the particular Document you're benchmarking. We use apollo-rs on Documents that are MBs in size (as suppose to 57KB in the example you provided), and we are yet to observe such a large spike in parse times. I'll need to investigate this a bit more. |
It looks like this issue is common for graphql parsers gqlparser, async-graphql-parser, and graphql-parser. While I wasn't able to make the scaling of these queries better overall, reducing the number of allocations in the lexer does improve the performance overall and seems to make it the fastest parsing option of the bunch. Maybe this could go further in certain cases with rust-analyzer/rowan#119. I more or less hit a wall with all CPU time dedicated to parsing the selection set fields. Here are some benchmarks with the available Rust parsers: https://github.com/allancalix/graphql-benchmark. Baseline small query
Pathological query
|
whoaaa thank you so much for putting all this work in for benchmarking @allancalix! i really appreciate it! There are definitely a whole bunch of improvements we can make when it comes to parser's performance. The work you did in #294 is one way to go about it, there is also an idea have a streaming interface (like in #115) for the lexer, or simply have the parser consume lexer's tokens without having that extra alloc at all. I realise I won't have enough time to think of a direction for us to take this until after GraphQL Summit happening in the first week of October. This goes in my backlog for October though. |
I've actually done both of these things to solve some bottlenecks for my use case. It's fairly rough currently, but once I get a chance to clean it up I'd be happy to upstream the changes if you'd be willing to review the PR. I included the excellent work done in #115 in additional to removing all the allocations from the Can see the direction of the changes here: main...allancalix:apollo-rs:finite-state-lexer. I've observed ~40-50% decrease in parse times for both simple and complex queries using the new lexer. |
Description
I noticed that parse times increase with query times more than I'd expect. I suspect that this has to do with the number of allocations happening during lexing/parsing as switching to jemalloc improved things ~15%. I'm not sure if it's something specific to this query or if any query of this size that sees the increase.
10 aliased fields
100 aliased fields
1000 aliased fields
Steps to reproduce
Expected result
Parse time for large queries should grow more slowly.
Actual result
Every 10x increase in number of selections increases parse times by > 800%.
Environment
apollo-rs
apollo-parserrevision = HEAD
The text was updated successfully, but these errors were encountered: