RESOLVED FIXED292147
REGRESSION (291398@main): Slower String.prototype.split with result length < 100
https://bugs.webkit.org/show_bug.cgi?id=292147
Summary REGRESSION (291398@main): Slower String.prototype.split with result length < 100
Dylan Conway
Reported 2025-04-28 01:32:53 PDT
Created attachment 475061 [details] out.js The recent `Array.prototype.indexOf` (e1b9447) optimization seems to cause a performance regression in `String.prototype.split`. This only applies to result lengths less than 100 because the extra work involved for the optimization (WeakGCMap.ensureValue) happens when it is less than 100. out.js is a bundled script that uses the `convert-csv-to-json` package to read a csv (37 cols, 130453 rows) into json. Comparing main and a build with `atomStringsArrayLimit` set to 20 to avoid the optimization, the results are: ``` > hyperfine -n "main" "../webkit-main/Tools/Scripts/run-jsc out.js" -n "atomStringArrayLimit=20" "./Tools/Scripts/run-jsc out.js" --warmup 5 Benchmark 1: main Time (mean ± σ): 571.2 ms ± 4.7 ms [User: 511.0 ms, System: 78.2 ms] Range (min … max): 561.9 ms … 576.7 ms 10 runs Benchmark 2: atomStringArrayLimit=20 Time (mean ± σ): 258.7 ms ± 2.8 ms [User: 219.7 ms, System: 57.2 ms] Range (min … max): 255.3 ms … 263.4 ms 11 runs Summary atomStringArrayLimit=20 ran 2.21 ± 0.03 times faster than main ``` another example, splitting the csv by line then comma: ``` // split-csv-37-cols.js const csv = readFile("input-37-cols.csv"); csv.split("\n").forEach(line => { line.split(","); }); ``` results: ``` > hyperfine -n "main" "../webkit-main/Tools/Scripts/run-jsc split-csv-37-cols.js" -n "atomStringArrayLimit=20" "./Tools/Scripts/run-jsc split-csv-37-cols.js" --warmup 5 Benchmark 1: main Time (mean ± σ): 458.1 ms ± 5.8 ms [User: 380.8 ms, System: 68.9 ms] Range (min … max): 451.5 ms … 468.0 ms 10 runs Benchmark 2: atomStringArrayLimit=20 Time (mean ± σ): 168.3 ms ± 2.2 ms [User: 107.3 ms, System: 47.4 ms] Range (min … max): 166.7 ms … 176.2 ms 17 runs Summary atomStringArrayLimit=20 ran 2.72 ± 0.05 times faster than main ``` input csv: https://github.com/Schlumberger/hackathon/blob/master/backend/dataset/data-large.csv Originally reported here https://github.com/oven-sh/bun/issues/17373
Attachments
out.js (11.82 KB, text/javascript)
2025-04-28 01:32 PDT, Dylan Conway
no flags
Radar WebKit Bug Importer
Comment 1 2025-05-05 01:33:13 PDT
Vassili Bykov
Comment 2 2025-05-07 10:31:17 PDT
EWS
Comment 3 2025-05-08 17:02:11 PDT
Committed 294689@main (d84f22e0d2e4): <https://commits.webkit.org/294689@main> Reviewed commits have been landed. Closing PR #45069 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.