Commit 3130bd5
committed
[JSC] Use the generic path in
https://bugs.webkit.org/show_bug.cgi?id=319023
Reviewed by Yusuke Suzuki.
For a global RegExp replace with a single match (rangeCount == 2, separatorCount == 1),
we create two substring StringImpls and concatenate them with jsString(). But when the
result is short, jsString() flattens it via tryMakeString() anyway, so this costs three
allocations and a double copy — strictly slower than the generic single-allocation path
below. This hits the common thousands-separator idiom
`String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ",")` for 4-6 digit numbers.
Take the special case only when jsString() would actually make a rope. The threshold is
extracted into shouldMakeRope() in JSString.h and shared with the jsString() overloads.
Baseline Patched
string-replace-generic 19.7240+-0.6320 ^ 14.7327+-0.3753 ^ definitely 1.3388x faster
string-replace-regexp-global-thousands-separator
153.5817+-1.6965 ^ 120.7386+-1.0667 ^ definitely 1.2720x faster
string-replace-regexp-global-single-match
152.1385+-0.4575 ^ 102.3380+-0.7269 ^ definitely 1.4866x faster
Tests: JSTests/microbenchmarks/string-replace-regexp-global-single-match.js
JSTests/microbenchmarks/string-replace-regexp-global-thousands-separator.js
* JSTests/microbenchmarks/string-replace-regexp-global-single-match.js: Added.
(test):
* JSTests/microbenchmarks/string-replace-regexp-global-thousands-separator.js: Added.
(test):
* Source/JavaScriptCore/runtime/JSString.h:
(JSC::shouldMakeRope):
* Source/JavaScriptCore/runtime/OperationsInlines.h:
(JSC::jsString):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::jsSpliceSubstringsWithSeparators):
(JSC::jsSpliceSubstringsWithSeparator):
Canonical link: https://commits.webkit.org/317282@mainjsSpliceSubstringsWithSeparator(s) for short two-range results1 parent 430a1af commit 3130bd5
6 files changed
Lines changed: 100 additions & 28 deletions
File tree
- JSTests/microbenchmarks
- Source/JavaScriptCore/runtime
Lines changed: 26 additions & 0 deletions
| 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 | + | |
Lines changed: 19 additions & 0 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
946 | 946 | | |
947 | 947 | | |
948 | 948 | | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
949 | 956 | | |
950 | 957 | | |
951 | 958 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
98 | 96 | | |
99 | 97 | | |
100 | 98 | | |
| |||
125 | 123 | | |
126 | 124 | | |
127 | 125 | | |
128 | | - | |
129 | | - | |
130 | | - | |
| 126 | + | |
131 | 127 | | |
132 | 128 | | |
133 | 129 | | |
| |||
204 | 200 | | |
205 | 201 | | |
206 | 202 | | |
207 | | - | |
208 | | - | |
209 | | - | |
| 203 | + | |
210 | 204 | | |
211 | 205 | | |
212 | 206 | | |
| |||
244 | 238 | | |
245 | 239 | | |
246 | 240 | | |
247 | | - | |
248 | | - | |
249 | | - | |
| 241 | + | |
250 | 242 | | |
251 | 243 | | |
252 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
385 | 387 | | |
386 | 388 | | |
387 | 389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
| |||
244 | 254 | | |
245 | 255 | | |
246 | 256 | | |
247 | | - | |
| 257 | + | |
248 | 258 | | |
249 | 259 | | |
250 | 260 | | |
| |||
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
263 | | - | |
264 | | - | |
265 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
266 | 292 | | |
267 | 293 | | |
268 | 294 | | |
| |||
1199 | 1225 | | |
1200 | 1226 | | |
1201 | 1227 | | |
1202 | | - | |
| 1228 | + | |
1203 | 1229 | | |
1204 | 1230 | | |
1205 | 1231 | | |
| |||
1245 | 1271 | | |
1246 | 1272 | | |
1247 | 1273 | | |
1248 | | - | |
| 1274 | + | |
1249 | 1275 | | |
1250 | 1276 | | |
1251 | 1277 | | |
| |||
1406 | 1432 | | |
1407 | 1433 | | |
1408 | 1434 | | |
1409 | | - | |
| 1435 | + | |
1410 | 1436 | | |
1411 | 1437 | | |
1412 | 1438 | | |
1413 | 1439 | | |
1414 | 1440 | | |
1415 | | - | |
| 1441 | + | |
1416 | 1442 | | |
1417 | 1443 | | |
1418 | 1444 | | |
| |||
0 commit comments