Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
serde with custom ESTree serializerserde with custom ESTree serializer
8fb55bf to
7df04c9
Compare
CodSpeed Performance ReportMerging #9256 will improve performances by 24.22%Comparing Summary
Benchmarks breakdown
|
f81c8b3 to
46b9151
Compare
7df04c9 to
4232680
Compare
4232680 to
beea0cc
Compare
beea0cc to
53d9342
Compare
|
#9259 adapted @oxc-parser/wasm NPM package to transfer AST to JS as a JSON string. So this PR now plays nicely with that NPM package.
So I think we can merge this now. |
Merge activity
|

Replace
serdewith a custom serializer specialized for writing JSON.impl Serialize->impl ESTree. I've called itESTreein case we want to add e.g.impl Babellater on.The main motivation is that with control of the serializer, we can make it stateful, so we can extend it to, for example, omit TS fields based on a flag. This is pretty much impossible with
serde's interface.But a side-effect of the simpler implementation is that it's also more performant.
The usage of
ESTreetrait is very similar toserde::Serialize. Main differences:serializemethod is infallible. Does not return aResult.state = serializer.serialize_struct();instead ofmap = serializer.serialize_map();.state.serialize_field(...)instead ofmap.serialize_entry(...)."or other characters that require escaping in JSON).This is a breaking change, as it's possible downstream consumers are using
serdeto serialize our AST to other formats. I'd guess unlikely, but possible. We can always implementserde::Serializeas well asESTreefurther down the line if there's a demand.