Repository navigation
Make gql js faster - #4305
Make gql js faster#4305JoviDeCroock wants to merge 4 commits into
Conversation
|
Hi @JoviDeCroock, I'm @github-actions bot happy to help you with this PR 👋 Supported commandsPlease post this commands in separate comments and only one per comment:
|
71a9fe8 to
d492cb1
Compare
d492cb1 to
2d0415d
Compare
This comment has been minimized.
This comment has been minimized.
DetailsBenchmark output
🍳 Preparing HEAD... HEAD�[90m x �[0m�[32m45.51�[0m ops/sec �[90m±�[0m�[33m2.21�[0m�[36m%�[0m�[90m x �[0m2.18 MB/op�[90m (8 runs sampled)�[0m ⏱ Build Schema from Introspection �[32mHEAD�[0m�[90m x �[0m�[32m54.13�[0m ops/sec �[90m±�[0m�[32m0.67�[0m�[36m%�[0m�[90m x �[0m1.11 MB/op�[90m (11 runs sampled)�[0m ⏱ Execute Introspection Query �[32mHEAD�[0m�[90m x �[0m�[32m49.44�[0m ops/sec �[90m±�[0m�[33m2.37�[0m�[36m%�[0m�[90m x �[0m2.48 MB/op�[90m (8 runs sampled)�[0m ⏱ Parse introspection query HEAD�[90m x �[0m�[32m13,613�[0m ops/sec �[90m±�[0m�[32m0.16�[0m�[36m%�[0m�[90m x �[0m2.62 KB/op�[90m (35 runs sampled)�[0m ⏱ Print ktichen-sink query �[32mHEAD�[0m�[90m x �[0m�[32m2,696�[0m ops/sec �[90m±�[0m�[32m1.10�[0m�[36m%�[0m�[90m x �[0m875 Bytes/op�[90m (11 runs sampled)�[0m ⏱ Many repeated fields HEAD�[90m x �[0m�[32m 99.1�[0m ops/sec �[90m±�[0m�[32m0.38�[0m�[36m%�[0m�[90m x �[0m524 KB/op�[90m (20 runs sampled)�[0m ⏱ Validate Introspection Query �[32mHEAD�[0m�[90m x �[0m�[32m571�[0m ops/sec �[90m±�[0m�[32m0.33�[0m�[36m%�[0m�[90m x �[0m268 KB/op�[90m (14 runs sampled)�[0m ⏱ Validate Invalid Query �[32mHEAD�[0m�[90m x �[0m�[32m509�[0m ops/sec �[90m±�[0m�[32m0.19�[0m�[36m%�[0m�[90m x �[0m326 KB/op�[90m (14 runs sampled)�[0m ⏱ Validate SDL Document HEAD�[90m x �[0m�[32m67.11�[0m ops/sec �[90m±�[0m�[32m1.26�[0m�[36m%�[0m�[90m x �[0m221 KB/op�[90m (11 runs sampled)�[0m ⏱ Visit all AST nodes HEAD�[90m x �[0m�[32m302�[0m ops/sec �[90m±�[0m�[32m0.15�[0m�[36m%�[0m�[90m x �[0m310 KB/op�[90m (20 runs sampled)�[0m ⏱ Visit all AST nodes in parallel �[32mHEAD�[0m�[90m x �[0m�[32m28.95�[0m ops/sec �[90m±�[0m�[32m0.53�[0m�[36m%�[0m�[90m x �[0m1.23 MB/op�[90m (7 runs sampled)�[0m |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
| } else { | ||
| node = Object.defineProperties( |
There was a problem hiding this comment.
This is a massive deopt, maybe we could keep this in by i.e. rather than copying the node just returning the string if that's what the edit is symbolising
DetailsBenchmark output
🍳 Preparing HEAD... �[32mHEAD�[0m�[90m x �[0m�[32m44.56�[0m ops/sec �[90m±�[0m�[32m1.54�[0m�[36m%�[0m�[90m x �[0m2.18 MB/op�[90m (8 runs sampled)�[0m ⏱ Build Schema from Introspection HEAD�[90m x �[0m�[32m51.34�[0m ops/sec �[90m±�[0m�[32m1.30�[0m�[36m%�[0m�[90m x �[0m1.11 MB/op�[90m (11 runs sampled)�[0m ⏱ Execute Introspection Query HEAD�[90m x �[0m�[32m49.17�[0m ops/sec �[90m±�[0m�[33m3.65�[0m�[36m%�[0m�[90m x �[0m2.48 MB/op�[90m (8 runs sampled)�[0m ⏱ Parse introspection query HEAD�[90m x �[0m�[32m13,239�[0m ops/sec �[90m±�[0m�[33m2.48�[0m�[36m%�[0m�[90m x �[0m2.62 KB/op�[90m (33 runs sampled)�[0m ⏱ Print kitchen-sink query �[32mHEAD�[0m�[90m x �[0m�[32m9,620�[0m ops/sec �[90m±�[0m�[32m0.28�[0m�[36m%�[0m�[90m x �[0m2.14 KB/op�[90m (25 runs sampled)�[0m ⏱ Many repeated fields �[32mHEAD�[0m�[90m x �[0m�[32m99.53�[0m ops/sec �[90m±�[0m�[32m0.35�[0m�[36m%�[0m�[90m x �[0m524 KB/op�[90m (21 runs sampled)�[0m ⏱ Validate Introspection Query HEAD�[90m x �[0m�[32m553�[0m ops/sec �[90m±�[0m�[33m3.91�[0m�[36m%�[0m�[90m x �[0m268 KB/op�[90m (14 runs sampled)�[0m ⏱ Validate Invalid Query �[32mHEAD�[0m�[90m x �[0m�[32m502�[0m ops/sec �[90m±�[0m�[32m0.70�[0m�[36m%�[0m�[90m x �[0m326 KB/op�[90m (14 runs sampled)�[0m ⏱ Validate SDL Document HEAD�[90m x �[0m�[33m61.47�[0m ops/sec �[90m±�[0m�[33m2.66�[0m�[36m%�[0m�[90m x �[0m221 KB/op�[90m (10 runs sampled)�[0m ⏱ Visit all AST nodes HEAD�[90m x �[0m�[33m290�[0m ops/sec �[90m±�[0m�[33m4.58�[0m�[36m%�[0m�[90m x �[0m310 KB/op�[90m (19 runs sampled)�[0m ⏱ Visit all AST nodes in parallel HEAD�[90m x �[0m�[32m28.49�[0m ops/sec �[90m±�[0m�[32m1.99�[0m�[36m%�[0m�[90m x �[0m1.23 MB/op�[90m (7 runs sampled)�[0m |
Might want to make the PR title a bit more specific tho :) |
|
After evaluation it doesn't look safe to remove property-descriptors 😅 this would be a breaking change |
Motivation: Share traversal for callbacks that reduce AST nodes. Related: graphql#4305 (comment)
Motivation: Share traversal for callbacks that reduce AST nodes. Related: graphql#4305 (comment)
graphql#4305 Official benchmark defaults; paired throughput changes (95% CIs). Comparisons are to v17.0.2 and this commit's immediate parent. Print kitchen sink document: | Runtime | vs v17.0.2 | vs immediate parent (94603a86b) | | --- | ---: | ---: | | Node 22.23.4 | +65.37% [+62.86%, +67.91%] | +32.00% [+30.29%, +33.73%] | | Node 24.22.2 | +70.25% [+68.16%, +72.36%] | +32.62% [+30.52%, +34.75%] | | Node 26.13.0 | +71.79% [+68.65%, +74.98%] | +32.17% [+29.80%, +34.59%] | | Node 27.0.0-alpha.0.0.0 | +52.48% [+49.93%, +55.06%] | +26.10% [+24.46%, +27.77%] | | Deno 2.9.8 | +61.84% [+52.52%, +71.72%] | +26.26% [+21.75%, +30.93%] | | Bun 1.4.4 | +80.89% [+75.48%, +86.46%] | +58.53% [+54.66%, +62.50%] | Print schema document: | Runtime | vs v17.0.2 | vs immediate parent (94603a86b) | | --- | ---: | ---: | | Node 22.23.4 | +9.37% [+2.24%, +16.99%] | +20.76% [+16.42%, +25.27%] | | Node 24.22.2 | +8.96% [+6.90%, +11.07%] | +18.89% [+16.36%, +21.48%] | | Node 26.13.0 | +7.00% [+2.25%, +11.97%] | +18.71% [+16.74%, +20.72%] | | Node 27.0.0-alpha.0.0.0 | -5.51% [-8.05%, -2.91%] | +15.50% [+12.60%, +18.47%] | | Deno 2.9.8 | +1.78% [-0.45%, +4.06%] | +17.95% [+15.26%, +20.69%] | | Bun 1.4.4 | +28.24% [+24.01%, +32.61%] | +41.90% [+34.42%, +49.79%] |
See: #4305 => with more to go...
While researching the numbers on v15 vs v16 I realised that our printer became much slower, the reason for this is two-fold.
joinfunction thatfilterseven when it's not neededvisitwe always recreate the full treeNow that second point we should discuss, as changing this might be considered a breaking change.
The way
visitcurrently behaves is that it is a reducer, whether or not the user returns a value it will always fully recreate the AST without any attempt at reusing parts of it, or as is the issue with our printer, it will recreate the full AST even if we aren't even remotely returning anything AST-like, we are returning strings 😅This PR can serve as an exploration of how we can improve things in v17 - I've seen issues flying around about refactoring the visitor, which this seems like a good trigger judging from how the performance is.