Repository navigation
Commit 6f5f583
committed
[JSC] JSON.parse should take keys found in JSONCache's name table, and their values, through a dedicated loop
https://bugs.webkit.org/show_bug.cgi?id=328615
rdar://190797577
Reviewed by Keith Miller.
JSON Tokenizing can be much faster if we are leveraging the skew of next
token. When parsing an object and having a key ("key"), then next only
valid token is colon (:). Based on this skew, we scan tokens more
quickly before going to the generic lexing code.
Given that JSON.parse is extremely frequently executed, we are tuning
super carefuly to make everything super efficient.
1. A key found in the name table was returned as an std::optional<ExistingProperty>,
folded into the Variant<ExistingProperty, Identifier> that the generic key lookup
produces, and paired with a consumedColon flag carried across the iteration. The
compiler ends up spilling them into the stack.
2. The lexer's position is a member, and the source is read one byte at a time, so
the compiler has to assume any byte store could change it. It was stored after
every advance, including after every digit of a number, and loaded again at the
top of the loop. The token after each value was likewise stored and loaded back
to decide whether the object continues.
This patch gives keys found in the name table their own loop, which reads the source through a local cursor
that stays in a register. For each key it matches the name, then reads a string value found in JSONCache's
source-text table, or an integer of at most nine digits without a sign, directly through the cursor,
stores the property with its transition, and dispatches on the separator byte.
Any other value is read by the lexer from the same position, and any other key takes the existing path for
that one property before returning to the loop.
ToT Patched
json-parse-object-reviver-same-value 78.3654+-0.2510 ? 78.9265+-0.3672 ?
todomvc-javascript-es5-json-parse 15.5418+-0.0712 ^ 12.6900+-0.0496 ^ definitely 1.2247x faster
vanilla-es2015-babel-webpack-todomvc-json-parse
25.2949+-0.1827 ^ 21.5578+-0.1615 ^ definitely 1.1734x faster
todomvc-javascript-es6-webpack-json-parse
27.4154+-0.1697 ^ 22.1923+-0.0995 ^ definitely 1.2354x faster
json-parse-array-reviver-same-value 56.1238+-0.1920 ^ 54.8521+-0.3038 ^ definitely 1.0232x faster
flight-todomvc-json-parse 16.0599+-0.0981 ^ 14.0560+-0.0439 ^ definitely 1.1426x faster
json-parse-object-reviver 80.3643+-0.2950 ? 80.9511+-0.5340 ?
json-parse-leaf-object 9.8980+-0.0613 ^ 7.6658+-0.0689 ^ definitely 1.2912x faster
vanilla-es2015-todomvc-json-parse 25.2668+-0.2169 ^ 21.5433+-0.0925 ^ definitely 1.1728x faster
json-parse-utf16-leaf-object 82.6690+-0.2743 ^ 62.4780+-0.4512 ^ definitely 1.3232x faster
json-parse-repeated-short-strings 9.3115+-0.0552 ^ 7.4934+-0.0350 ^ definitely 1.2426x faster
vanilla-todomvc-json-parse 18.8332+-0.0518 ^ 15.9560+-0.0715 ^ definitely 1.1803x faster
json-parse-utf16-nested-records 32.1751+-0.1018 ^ 28.4392+-0.1211 ^ definitely 1.1314x faster
json-parse-array-reviver 61.4988+-0.4369 60.5441+-0.5521 might be 1.0158x faster
json-parse-double 46.6939+-0.1455 ^ 45.6980+-0.3330 ^ definitely 1.0218x faster
json-parse-short-string-ids 108.9573+-1.1631 ^ 103.1068+-1.3449 ^ definitely 1.0567x faster
json-parse-int32-array 208.2562+-1.2047 ^ 195.6330+-0.9339 ^ definitely 1.0645x faster
<geometric> 37.0365+-0.0552 ^ 32.7853+-0.0497 ^ definitely 1.1297x faster
Test: JSTests/stress/json-parse-cached-integer-values.js
* JSTests/stress/json-parse-cached-integer-values.js: Added.
(shouldBe):
(parse):
(shouldThrow):
(iteration.p.of.prefixes.const.number.of.numbers.const.number.of.invalid.shouldThrow.shouldThrow.shouldThrow.shouldThrow.shouldThrow.join):
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::scanJSONIntegerDigits):
(JSC::reviverMode>::Lexer::lexNumber):
(JSC::requires):
(JSC::reviverMode>::Lexer::skipWhitespaceBeforeKey): Deleted.
* Source/JavaScriptCore/runtime/LiteralParser.h:
(JSC::LiteralParser::Lexer::end const):
(JSC::LiteralParser::Lexer::setPtr):
* Source/JavaScriptCore/runtime/ParseInt.h:
(JSC::parseInt):
Canonical link: https://commits.webkit.org/324783@main1 parent 7b78a52 commit 6f5f583
4 files changed
Lines changed: 462 additions & 257 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
0 commit comments