Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7658c6d1236fe89d94477d91983f8db321bde587
      
https://github.com/WebKit/WebKit/commit/7658c6d1236fe89d94477d91983f8db321bde587
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-06-29 (Mon, 29 Jun 2026)

  Changed paths:
    A JSTests/microbenchmarks/json-stringify-pretty-tab.js
    A JSTests/microbenchmarks/json-stringify-pretty.js
    A JSTests/stress/json-stringify-space-fast-path.js
    M Source/JavaScriptCore/runtime/JSONObject.cpp

  Log Message:
  -----------
  [JSC] Support space argument in `FastStringifier`
https://bugs.webkit.org/show_bug.cgi?id=318086

Reviewed by Yusuke Suzuki.

FastStringifier bails out whenever the space argument is not undefined,
so common pretty-printing calls like JSON.stringify(value, null, 2)
always run the general Stringifier, which is several times slower than
the fast path on typical config / logging shaped objects.

This patch resolves the gap inside FastStringifier and writes the
newline plus depth * gap indentation directly into the flat buffer.
Numbers and 8-bit string spaces are handled; boxed primitives keep
falling back since unwrapping them is observable, and so do 16-bit gap
strings since the gap is stored as Latin-1. append() is templatized on
HasGap so that the no-space instantiation compiles to the same code as
before; a runtime-checked version regressed json-stringify-int32-array
by 1.78x.

                                              baseline                  patched

json-stringify-int32-array                18.9412+-0.8168     ?     
19.1482+-0.7348        ? might be 1.0109x slower
json-stringify-many-objects              144.2817+-1.2609     ?    
145.7997+-0.7796        ? might be 1.0105x slower
json-stringify-empty-array                20.6268+-0.8005           
20.2796+-0.3744          might be 1.0171x faster
json-stringify-pretty-tab               1128.9899+-15.1355    ^    
274.4653+-3.0505        ^ definitely 4.1134x faster
json-stringify-array-replacer             13.6181+-0.1381     ?     
13.7487+-0.2907        ?
json-stringify-pretty                   1191.4510+-7.5572     ^    
301.6980+-4.2533        ^ definitely 3.9492x faster
json-stringify-many-objects-to-json       89.9216+-0.4452     ?     
90.5576+-1.0200        ?
vanilla-todomvc-json-stringify            40.9058+-0.6199     ^     
38.5172+-0.8057        ^ definitely 1.0620x faster

Tests: JSTests/microbenchmarks/json-stringify-pretty-tab.js
       JSTests/microbenchmarks/json-stringify-pretty.js
       JSTests/stress/json-stringify-space-fast-path.js

* JSTests/microbenchmarks/json-stringify-pretty-tab.js: Added.
* JSTests/microbenchmarks/json-stringify-pretty.js: Added.
* JSTests/stress/json-stringify-space-fast-path.js: Added.
(f):
(new.Date):
(show):
(const.space.of.spaces.const.value.of.values.catch):
(print.string_appeared_here.slowErr.JSON.stringify):
(print):
* Source/JavaScriptCore/runtime/JSONObject.cpp:
(JSC::gap):
(JSC::bufferMode>::setGap):
(JSC::bufferMode>::newLineAndIndentSize const):
(JSC::bufferMode>::appendNewLineAndIndentUnchecked):
(JSC::bufferMode>::append):
(JSC::bufferMode>::appendInt32Array):
(JSC::bufferMode>::stringify):

Canonical link: https://commits.webkit.org/316108@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to