RESOLVED FIXED 235996
Speed-up JSON.stringify() by avoiding "toJSON" property lookups
https://bugs.webkit.org/show_bug.cgi?id=235996
Summary Speed-up JSON.stringify() by avoiding "toJSON" property lookups
Alexey Shvayka
Reported 2022-02-01 18:42:07 PST
Speed-up JSON.stringify() by avoiding "toJSON" property lookups
Attachments
Patch (6.23 KB, patch)
2022-02-01 18:45 PST, Alexey Shvayka
no flags
Patch (7.95 KB, patch)
2022-02-02 08:52 PST, Alexey Shvayka
no flags
Alexey Shvayka
Comment 1 2022-02-01 18:45:49 PST
Alexey Shvayka
Comment 2 2022-02-01 18:46:11 PST
(In reply to Alexey Shvayka from comment #1) > Created attachment 450601 [details] > Patch r288790 patch json-stringify-empty-array 109.4195+-0.3423 ^ 89.3711+-0.2926 ^ definitely 1.2243x faster json-stringify-array-replacer 26.5174+-0.0323 26.5100+-0.0257 json-stringify-many-objects 243.2980+-2.4751 ^ 228.2883+-0.8872 ^ definitely 1.0657x faster json-stringify-many-objects-to-json 170.5229+-0.3290 ^ 152.2288+-0.4103 ^ definitely 1.1202x faster vanilla-todomvc-json-stringify 192.3345+-0.4409 ^ 185.5248+-0.2852 ^ definitely 1.0367x faster
Alexey Shvayka
Comment 3 2022-02-01 18:47:48 PST
Comment on attachment 450601 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=450601&action=review > Source/JavaScriptCore/ChangeLog:9 > + it accounts for 10-15% of running time. EmberJS* subtests rely on JSON.stringify() as MacBookPro17,1: VanillaJS-TodoMVC: 50ms Vanilla-ES2015-TodoMVC: 65ms JSON.stringify() takes 5-10ms, way slower on MiniBrowser than JSC shell for some reason.
Saam Barati
Comment 4 2022-02-01 18:53:23 PST
Comment on attachment 450601 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=450601&action=review > Source/JavaScriptCore/ChangeLog:20 > + While we could come up with a solution that doesn't involve creating StructureRareData > + for all structures we stringify, like keeping a list of StructureIDs w/o "toJSON" method, > + which will be correct as long as `m_hasFastObjectProperties || m_isJSArray` is true for all > + seen objects, that would probably miss some edge case, won't persist between JSON.stringify() > + calls, and won't speed-up structures with "toJSON" methods like Dates. Can you also include what your solution actually was, instead of potential alternate solutions? And how it works
Alexey Shvayka
Comment 5 2022-02-02 08:52:02 PST
Created attachment 450648 [details] Patch Expand ChangeLog on actual solution and handle CachedSpecialPropertyKey::ToJSON in more places.
Saam Barati
Comment 6 2022-02-02 09:09:28 PST
Comment on attachment 450648 [details] Patch r=me
Alexey Shvayka
Comment 7 2022-02-02 16:13:09 PST
Comment on attachment 450648 [details] Patch Thank you Saam!
EWS
Comment 8 2022-02-02 17:05:07 PST
Committed r289020 (246728@main): <https://commits.webkit.org/246728@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 450648 [details].
Radar WebKit Bug Importer
Comment 9 2022-02-02 17:06:24 PST
Note You need to log in before you can comment on or make changes to this bug.