Speed-up JSON.stringify() by avoiding "toJSON" property lookups
Created attachment 450601 [details] Patch
(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
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.
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
Created attachment 450648 [details] Patch Expand ChangeLog on actual solution and handle CachedSpecialPropertyKey::ToJSON in more places.
Comment on attachment 450648 [details] Patch r=me
Comment on attachment 450648 [details] Patch Thank you Saam!
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].
<rdar://problem/88409665>