Optimize JSON.stringify more
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
People
(Reporter: jandem, Unassigned)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Whiteboard: [js-perf-next])
V8 optimized JSON.stringify recently and they've written a blog post about this work:
How we made JSON.stringify more than twice as fast
On AWFY Chrome is now faster than us again on the json-stringify-inspector test in JetStream 3.
Their "side-effect-free fast path" is somewhat similar to the fast path we added in bug 1837410. They list some other optimizations (for example for escaping string characters) that are worth investigating. The post also mentions the Dragonbox library that's now used by both V8 and JSC for double-to-string conversion (this is covered by bug 1964738).
Updated•1 year ago
|
Comment 1•1 year ago
|
||
Yeah, the big things I remember from that post:
- segmented string buffers (which we've all decided are the right way to go but a bit of a nuisance to implement with what we have)
- quoting/escaping. This shows up a lot in profiles. Anything we can steal here would be good.
- double to string conversion
The iterative side-effect-free fast path sounds mostly the same, except that they can handle different string encodings (probably relying on the segmented approach?)
Also, I'd need to go look at the code again, but my impression is that their limitations on index-like keys might be more restrictive than ours, suggesting that the key iteration path might be more optimizable if we adopt tighter limits. (Then again, it might be the same already.)
| Reporter | ||
Comment 2•1 year ago
|
||
I experimented a bit with a segmented string builder for array-join and json-stringify in bug 1957918. I wasn't able to improve the numbers a lot with my prototype patch but I also didn't spend a lot of time on it so it's definitely possible we can do better.
Comment 3•7 months ago
|
||
js-perf-next: Moving this up in priority. This is the 10th biggest bucket in SP3 comparison reports, worth more than 0.5% overall. (It's worth noting that the comparison reports show that we're spending ~30% of our JSON.stringify time doing Nightly-only poisoning in arena_realloc.) This also shows up in JS3, most prominently in json-stringify-inspector, where we're ~40% behind.
Comment 4•6 months ago
|
||
Mayank attached some microbenchmarks to bug 2015256. The JSON2 profile looks similar to profiles I've seen from SP3/JS3: time spent reallocating in extractWellSized and in QuoteJSONString. The JSON1 profile looks like a case where V8's fast path for easy objects kicks in, leaving us 10x slower.
Description
•