Skip to content

AK+Everywhere: Recognise that surrogates in utf16 aren't all that common #4196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

alimpfard
Copy link
Contributor

@alimpfard alimpfard commented Apr 2, 2025

For the slight cost of counting code points when converting between encodings and a teeny bit of memory, this commit adds a fast path for all-happy utf-16 substrings and code point operations.

This seems to be a significant chunk of time spent in many regex benchmarks.

js benchmarks for fun:

SunSpider   Total                0.982  2.190           2.230
Kraken      Total                0.953  34.653          36.347
Octane      Total                1.003  222.273         221.690
JetStream   Total                0.998  275.303         275.777
JetStream3  Total                0.638  29.243          45.803
All Suites  Total                0.969  563.663         581.847

@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch from 7b0af44 to 9e91f87 Compare April 2, 2025 17:09
@github-actions github-actions bot added the conflicts Pull request has merge conflicts that need resolution label Apr 9, 2025
Copy link

github-actions bot commented Apr 9, 2025

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch from 9e91f87 to 7974e81 Compare April 9, 2025 13:29
@github-actions github-actions bot removed the conflicts Pull request has merge conflicts that need resolution label Apr 9, 2025
@awesomekling
Copy link
Member

js benchmarks for fun:

SunSpider   Total                0.982  2.190           2.230
Kraken      Total                0.953  34.653          36.347
Octane      Total                1.003  222.273         221.690
JetStream   Total                0.998  275.303         275.777
JetStream3  Total                0.638  29.243          45.803
All Suites  Total                0.969  563.663         581.847

This looks disastrous (0.63x on JetStream3) but I kinda assume you were running this in your weird multithreading mode? 😅

When pasting JS benchmark results, please include the whole dump so we can see how each subtest was affected.

@alimpfard
Copy link
Contributor Author

🤔 0.6 is good though? 40% faster?
I'll start a run tomorrow with the normal single-thread thing and report those instead.

@LucasChollet
Copy link
Contributor

I read it the other way around. As you can see there it's usually old time and then new time. So to me, the change makes JetStream3 go 15s slower.

@alimpfard
Copy link
Contributor Author

Huh. I guess we'll see after the non-weird runs lol

@alimpfard
Copy link
Contributor Author

Here are the results with the master branch of js-benchmarks:

Suite       Test                                   Speedup  Old (Mean ± Range)        New (Mean ± Range)
----------  -----------------------------------  ---------  ------------------------  ------------------------
SunSpider   3d-cube.js                               1      0.020 ± 0.020 … 0.020     0.020 ± 0.020 … 0.020
SunSpider   3d-morph.js                              1      0.030 ± 0.030 … 0.030     0.030 ± 0.030 … 0.030
SunSpider   3d-raytrace.js                           1.167  0.023 ± 0.020 … 0.030     0.020 ± 0.020 … 0.020
SunSpider   access-binary-trees.js                   1.222  0.037 ± 0.030 … 0.040     0.030 ± 0.030 … 0.030
SunSpider   access-fannkuch.js                       1      0.030 ± 0.030 … 0.030     0.030 ± 0.030 … 0.030
SunSpider   access-nbody.js                          0.833  0.017 ± 0.010 … 0.020     0.020 ± 0.020 … 0.020
SunSpider   access-nsieve.js                         1      0.020 ± 0.020 … 0.020     0.020 ± 0.020 … 0.020
SunSpider   bitops-3bit-bits-in-byte.js              1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   bitops-bits-in-byte.js                   1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   bitops-bitwise-and.js                    1      0.210 ± 0.210 … 0.210     0.210 ± 0.210 … 0.210
SunSpider   bitops-nsieve-bits.js                    1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   controlflow-recursive.js                 1.167  0.047 ± 0.040 … 0.050     0.040 ± 0.040 … 0.040
SunSpider   crypto-aes.js                            1      0.020 ± 0.020 … 0.020     0.020 ± 0.020 … 0.020
SunSpider   crypto-md5.js                            1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   crypto-sha1.js                           1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   date-format-tofte.js                     1      0.040 ± 0.040 … 0.040     0.040 ± 0.040 … 0.040
SunSpider   date-format-xparb.js                     1      0.030 ± 0.030 … 0.030     0.030 ± 0.030 … 0.030
SunSpider   math-cordic.js                           1.125  0.030 ± 0.030 … 0.030     0.027 ± 0.020 … 0.030
SunSpider   math-partial-sums.js                     1      0.070 ± 0.070 … 0.070     0.070 ± 0.070 … 0.070
SunSpider   math-spectral-norm.js                    1      0.010 ± 0.010 … 0.010     0.010 ± 0.010 … 0.010
SunSpider   regexp-dna.js                            0.934  0.283 ± 0.280 … 0.290     0.303 ± 0.290 … 0.330
SunSpider   string-base64.js                         1      0.020 ± 0.020 … 0.020     0.020 ± 0.020 … 0.020
SunSpider   string-fasta.js                          1.02   0.173 ± 0.170 … 0.180     0.170 ± 0.170 … 0.170
SunSpider   string-tagcloud.js                       1.029  0.117 ± 0.110 … 0.120     0.113 ± 0.110 … 0.120
SunSpider   string-unpack-code.js                    1      0.120 ± 0.120 … 0.120     0.120 ± 0.120 … 0.120
SunSpider   string-validate-input.js                 1      0.030 ± 0.030 … 0.030     0.030 ± 0.030 … 0.030
Kraken      ai-astar.js                              0.997  1.207 ± 1.200 … 1.220     1.210 ± 1.200 … 1.220
Kraken      audio-beat-detection.js                  0.994  1.093 ± 1.090 … 1.100     1.100 ± 1.090 … 1.110
Kraken      audio-dft.js                             0.996  0.753 ± 0.740 … 0.760     0.757 ± 0.750 … 0.760
Kraken      audio-fft.js                             1      0.970 ± 0.970 … 0.970     0.970 ± 0.970 … 0.970
Kraken      audio-oscillator.js                      1.003  1.087 ± 1.080 … 1.090     1.083 ± 1.080 … 1.090
Kraken      imaging-darkroom.js                      1.003  1.063 ± 1.060 … 1.070     1.060 ± 1.050 … 1.070
Kraken      imaging-desaturate.js                    1.013  1.290 ± 1.280 … 1.300     1.273 ± 1.270 … 1.280
Kraken      imaging-gaussian-blur.js                 1.004  5.467 ± 5.420 … 5.550     5.447 ± 5.390 … 5.540
Kraken      json-parse-financial.js                  1      0.050 ± 0.050 … 0.050     0.050 ± 0.050 … 0.050
Kraken      json-stringify-tinderbox.js              1      0.100 ± 0.100 … 0.100     0.100 ± 0.100 … 0.100
Kraken      stanford-crypto-aes.js                   0.993  0.483 ± 0.480 … 0.490     0.487 ± 0.480 … 0.490
Kraken      stanford-crypto-ccm.js                   1      0.400 ± 0.400 … 0.400     0.400 ± 0.400 … 0.400
Kraken      stanford-crypto-pbkdf2.js                1.008  0.847 ± 0.840 … 0.850     0.840 ± 0.840 … 0.840
Kraken      stanford-crypto-sha256-iterative.js      1.019  0.350 ± 0.350 … 0.350     0.343 ± 0.340 … 0.350
Octane      box2d.js                                 1.006  2.223 ± 2.220 … 2.230     2.210 ± 2.210 … 2.210
Octane      code-load.js                             1.034  2.117 ± 2.110 … 2.120     2.047 ± 2.010 … 2.110
Octane      crypto.js                                0.992  5.117 ± 5.070 … 5.150     5.160 ± 5.120 … 5.180
Octane      deltablue.js                             1      2.010 ± 2.010 … 2.010     2.010 ± 2.010 … 2.010
Octane      earley-boyer.js                          1.01   11.903 ± 11.880 … 11.940  11.783 ± 11.780 … 11.790
Octane      gbemu.js                                 1.001  2.313 ± 2.310 … 2.320     2.310 ± 2.290 … 2.320
Octane      mandreel.js                              1.017  8.150 ± 8.090 … 8.190     8.013 ± 7.980 … 8.030
Octane      navier-stokes.js                         0.997  2.093 ± 2.090 … 2.100     2.100 ± 2.070 … 2.120
Octane      pdfjs.js                                 1.001  2.847 ± 2.840 … 2.850     2.843 ± 2.830 … 2.860
Octane      raytrace.js                              1.005  5.060 ± 5.050 … 5.070     5.037 ± 5.030 … 5.040
Octane      regexp.js                                0.996  17.413 ± 17.240 … 17.650  17.477 ± 17.410 … 17.540
Octane      richards.js                              1      2.003 ± 2.000 … 2.010     2.003 ± 2.000 … 2.010
Octane      splay.js                                 1.001  2.417 ± 2.410 … 2.420     2.413 ± 2.410 … 2.420
Octane      typescript.js                            1.008  16.150 ± 16.130 … 16.170  16.020 ± 16.010 … 16.030
Octane      zlib.js                                  1.014  52.003 ± 51.530 … 52.300  51.300 ± 51.220 … 51.400
JetStream   bigfib.cpp.js                            0.999  9.407 ± 9.380 … 9.460     9.413 ± 9.390 … 9.450
JetStream   cdjs.js                                  1.014  6.200 ± 6.180 … 6.220     6.113 ± 6.100 … 6.130
JetStream   container.cpp.js                         0.995  35.317 ± 35.110 … 35.590  35.510 ± 35.430 … 35.590
JetStream   dry.c.js                                 1.012  23.170 ± 22.900 … 23.430  22.897 ± 22.720 … 23.250
JetStream   float-mm.c.js                            1.008  23.527 ± 23.460 … 23.600  23.347 ± 23.110 … 23.540
JetStream   gcc-loops.cpp.js                         1      -1.000 ± -1.000 … -1.000  -1.000 ± -1.000 … -1.000
JetStream   hash-map.js                              0.989  3.827 ± 3.800 … 3.860     3.870 ± 3.820 … 3.930
JetStream   n-body.c.js                              1.004  35.340 ± 35.210 … 35.490  35.187 ± 34.870 … 35.700
JetStream   quicksort.c.js                           1.021  5.243 ± 5.130 … 5.380     5.133 ± 5.100 … 5.180
JetStream   towers.c.js                              0.983  6.930 ± 6.900 … 6.950     7.053 ± 7.010 … 7.130
JetStream3  js-tokens.js                            16.735  16.233 ± 16.220 … 16.240  0.970 ± 0.970 … 0.970
JetStream3  lazy-collections.js                      1.006  1.720 ± 1.710 … 1.730     1.710 ± 1.700 … 1.720
JetStream3  raytrace-private-class-fields.js         1.011  6.403 ± 6.390 … 6.420     6.337 ± 6.320 … 6.360
JetStream3  raytrace-public-class-fields.js          1.011  5.023 ± 5.020 … 5.030     4.970 ± 4.960 … 4.980
JetStream3  sync-file-system.js                      1.019  3.050 ± 3.000 … 3.090     2.993 ± 2.980 … 3.010
SunSpider   Total                                    1.002  1.427                     1.423
Kraken      Total                                    1.003  15.160                    15.120
Octane      Total                                    1.008  133.820                   132.727
JetStream   Total                                    1.003  147.960                   147.523
JetStream3  Total                                    1.91   32.430                    16.980
All Suites  Total                                    1.054  330.797                   313.773

@awesomekling
Copy link
Member

Here are the results with the master branch of js-benchmarks:

That's a juicy 16x speedup right there :)

@github-actions github-actions bot added the conflicts Pull request has merge conflicts that need resolution label Apr 11, 2025
Copy link

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch from 7974e81 to 8a2cadb Compare April 20, 2025 21:15
@github-actions github-actions bot removed the conflicts Pull request has merge conflicts that need resolution label Apr 20, 2025
@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch 2 times, most recently from cf8cac2 to 5d0003f Compare April 21, 2025 12:41
@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch from 5d0003f to a3dbca9 Compare April 23, 2025 04:52
For the slight cost of counting code points when converting between
encodings and a teeny bit of memory, this commit adds a fast path for
all-happy utf-16 substrings and code point operations.

This seems to be a significant chunk of time spent in many regex
benchmarks.
@alimpfard alimpfard force-pushed the utf16-stop-length-abuse-call-8-11-fast-path branch from a3dbca9 to b50a10c Compare April 23, 2025 05:01
Copy link
Member

@ADKaster ADKaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm pending ASAN results. Should wait for GCC asan as well.

@ADKaster
Copy link
Member

Well I say that, but ASAN is unhappy. .. with Alex?

https://github.com/LadybirdBrowser/ladybird/actions/runs/14610340278/job/40987086963?pr=4196#step:18:32

Something fishy with destruction of painting render thread in WebContent I guess.

@ADKaster
Copy link
Member

whatever, I'm merging this. hit a table CSS test flake this time.

@ADKaster ADKaster merged commit eea8173 into LadybirdBrowser:master Apr 23, 2025
10 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants