[webkit-changes] [WebKit/WebKit] 1f2410: [JSC] Make JSON.parse even faster with identifier-...

Yusuke Suzuki noreply at github.com
Thu Aug 31 10:32:15 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 1f24101561da7ba92edc5b8efab210af2393c7a6
      https://github.com/WebKit/WebKit/commit/1f24101561da7ba92edc5b8efab210af2393c7a6
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2023-08-31 (Thu, 31 Aug 2023)

  Changed paths:
    A JSTests/microbenchmarks/todomvc-javascript-es5-json-parse.js
    A JSTests/microbenchmarks/todomvc-javascript-es6-webpack-json-parse.js
    A JSTests/stress/ensure-json-put-does-not-see-may-be-prototype.js
    M Source/JavaScriptCore/runtime/JSObject.cpp
    M Source/JavaScriptCore/runtime/JSObject.h
    M Source/JavaScriptCore/runtime/JSObjectInlines.h
    M Source/JavaScriptCore/runtime/LiteralParser.cpp
    M Source/JavaScriptCore/runtime/LiteralParser.h
    M Source/JavaScriptCore/runtime/StructureInlines.h

  Log Message:
  -----------
  [JSC] Make JSON.parse even faster with identifier-hint and putDirect fast path
https://bugs.webkit.org/show_bug.cgi?id=260921
rdar://114715367

Reviewed by Keith Miller.

This patch accelerates JSON.parse even more by introducing two optimizations.

1. We add IndeitiferHint to JSON.parse's lexing fast path. This slightly changes how we scan the string,
   given the information that this will be used as an identifier for objects. We swap the ordering of
   comparison for UChar JSON.parse in isSafeStringCharacterForIdentifier, since identifier is, in almost all cases, ASCII!
2. We found that `putDirect` function call in JSON.parse fast path is costly, and if we can inline the fast cases of this,
   we can get performance boost. Given that this is JSON.parse's fast path for JSObject creation, we know that
    a. The object is definitely JSFinalObject.
    b. The object rarely has duplicate properties.
    c. Many same-shaped objects would be created from JSON. Thus very likely, there is already an existing Structure.
   Based on this observation, we add super fast path in JSON.parse which does existing Structure transition quickly.
3. Added JSON.parse microbenchmarks extracted from Speedometer3.0.

                                                     ToT                     Patched

todomvc-javascript-es5-json-parse              58.1822+-0.2031     ^     52.2885+-0.3449        ^ definitely 1.1127x faster
vanilla-es2015-babel-webpack-todomvc-json-parse
                                               57.4813+-0.5289     ^     54.7597+-0.1805        ^ definitely 1.0497x faster
todomvc-javascript-es6-webpack-json-parse
                                               89.5463+-0.5104     ^     83.3758+-0.5923        ^ definitely 1.0740x faster
vanilla-es2015-todomvc-json-parse              57.2404+-0.4405     ^     54.6702+-0.1448        ^ definitely 1.0470x faster
vanilla-todomvc-json-parse                     42.4967+-0.2446     ^     40.6605+-0.0723        ^ definitely 1.0452x faster

* JSTests/microbenchmarks/todomvc-javascript-es5-json-parse.js: Added.
(test):
* JSTests/microbenchmarks/todomvc-javascript-es6-webpack-json-parse.js: Added.
(test):
* Source/JavaScriptCore/runtime/JSObject.cpp:
(JSC::JSObject::putDirectForJSONSlow):
* Source/JavaScriptCore/runtime/JSObject.h:
* Source/JavaScriptCore/runtime/JSObjectInlines.h:
(JSC::JSObject::putDirectInternal):
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::isJSONWhiteSpace):
(JSC::LiteralParser<CharType>::Lexer::lex):
(JSC::LiteralParser<CharType>::Lexer::next):
(JSC::LiteralParser<CharType>::Lexer::nextMaybeIdentifier):
(JSC::isSafeStringCharacterForIdentifier):
(JSC::LiteralParser<CharType>::Lexer::lexString):
(JSC::LiteralParser<CharType>::parseRecursively):
* Source/JavaScriptCore/runtime/LiteralParser.h:
* Source/JavaScriptCore/runtime/StructureInlines.h:
(JSC::Structure::addPropertyTransitionToExistingStructureImpl):

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




More information about the webkit-changes mailing list