Repository navigation
Commit 609fc1c
committed
[JSC] JSON.parse should match more repeated string values against the source text
https://bugs.webkit.org/show_bug.cgi?id=329490
rdar://191351073
Reviewed by Keith Miller.
JSONCache matched a repeated string value against the source text only when its
quoted text fit in the short value table's 32 characters. A longer value was
scanned for its closing quote before m_longJSStrings was consulted, so every
repeat still paid for the scan.
This patch replaces existing m_longJSStrings with a 4-way table of 256 entries
that is looked up both before a property value is lexed and after.
1. findLongString searches at most 64 characters for the closing quote and
indexes the value by its length and its first and last 8 characters, or by
its first 8 and characters 56 to 63 when it is 64 characters or longer. A hit
skips lexing the value, and so does a miss on a value without escapes,
which addLongString records right away.
2. makeLongJSString looks up and records every value of 17 to 256 characters
after it is lexed. A value that needs escapes is recorded with a key bit
cleared, so that only this lookup finds it.
3. Values of 64 characters or more are also kept in a direct-mapped table
indexed by the whole value, so that values sharing their first 64
characters are still shared when more of them repeat than a set holds.
4. An entry packs its JSString with its text length and 10 hash bits into 8
bytes, using the low bits of the aligned pointer, so a probe reads the
JSString only when the key matches.
The short value table moves to the same entries, grows from 64 to 128 values,
and compares both ways of a set against a single load of the source.
Test: JSTests/stress/json-parse-repeated-long-string-values.js
* JSTests/stress/json-parse-repeated-long-string-values.js: Added.
(shouldBe):
(try.catch):
(try.a.nb.catch):
(try.shouldBe):
(try.gc):
(try.string_appeared_here.catch):
* Source/JavaScriptCore/runtime/JSONCache.cpp:
(JSC::JSONCache::recordableName):
(JSC::JSONCache::addLongString):
* Source/JavaScriptCore/runtime/JSONCache.h:
(JSC::JSONCache::StringEntry::makeKey):
(JSC::JSONCache::StringEntry::StringEntry):
(JSC::JSONCache::StringEntry::string const):
(JSC::JSONCache::StringEntry::key const):
(JSC::JSONCache::StringEntry::textLength const):
(JSC::JSONCache::clearJSStrings):
(JSC::JSONCache::textMatches):
* Source/JavaScriptCore/runtime/JSONCacheInlines.h:
(JSC::JSONCache::makeJSString):
(JSC::JSONCache::hasUnsafeStringCharacter):
(JSC::JSONCache::longStringMatches):
(JSC::JSONCache::insertLongString):
(JSC::JSONCache::makeLongJSString):
(JSC::JSONCache::loadTextWindow):
(JSC::JSONCache::textMatches):
(JSC::JSONCache::stringPrefix):
(JSC::JSONCache::stringIndex):
(JSC::JSONCache::StringTable::match const):
(JSC::JSONCache::StringTable::insert):
(JSC::JSONCache::findShortString):
(JSC::JSONCache::longStringHash):
(JSC::JSONCache::longStringHashBits):
(JSC::JSONCache::longStringIndex):
(JSC::JSONCache::secondaryLongStringIndex):
(JSC::JSONCache::boundedValueLength):
(JSC::JSONCache::longTextMatches):
(JSC::JSONCache::findLongString):
(JSC::JSONCache::findOrCreateString):
(JSC::JSONCache::findString const): Deleted.
* Source/JavaScriptCore/runtime/LiteralParser.cpp:
(JSC::reviverMode>::makeJSString):
(JSC::reviverMode>::Lexer::currentStringIsSourceText const):
(JSC::reviverMode>::Lexer::cacheString):
(JSC::reviverMode>::Lexer::lexString):
(JSC::reviverMode>::parsePrimitiveValue):
(JSC::requires):
* Source/JavaScriptCore/runtime/LiteralParser.h:
(JSC::LiteralParser::Lexer::currentStringSource const):
Canonical link: https://commits.webkit.org/325346@main1 parent eaa7e09 commit 609fc1c
6 files changed
Lines changed: 624 additions & 110 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 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 46 | + | |
| 47 | + | |
50 | 48 | | |
51 | 49 | | |
52 | 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 | + | |
53 | 93 | | |
54 | 94 | | |
55 | 95 | | |
| |||
0 commit comments