RESOLVED FIXED 250112
[WTF] Integrate simdutf
https://bugs.webkit.org/show_bug.cgi?id=250112
Summary [WTF] Integrate simdutf
Jarred Sumner
Reported 2023-01-04 16:38:42 PST
simdutf is a fast text encoding/decoding library which supports UTF8 -> UTF16, UTF16 -> UTF8, and ascii validation. GitHub: https://github.com/simdutf/simdutf Bun uses simdutf for TextEncoder & TextDecoder (in the happy path) For this code: ``` var decoder = new TextDecoder(); var encoder = new TextEncoder(); var buf = encoder.encode( "not all ascii 🙂 🙃 1-2-3-4 abcdefghklmnopqrstuvwxyz".repeat(9999) ), buf1 = buf.slice(0, buf.length - 1), buf2 = buf.slice(0, buf.length - 2); var decoded = decoder.decode(buf), decoded1 = decoder.decode(buf1), decoded2 = decoder.decode(buf2); console.time("TextDecoder.decode"); decoder.decode(buf); console.timeEnd("TextDecoder.decode"); console.time("TextDecoder.decode"); decoder.decode(buf1); console.timeEnd("TextDecoder.decode"); console.time("TextDecoder.decode"); decoder.decode(buf2); console.timeEnd("TextDecoder.decode"); console.time("TextEncoder.encode"); encoder.encode(decoded); console.timeEnd("TextEncoder.encode"); console.time("TextEncoder.encode"); encoder.encode(decoded1); console.timeEnd("TextEncoder.encode"); console.time("TextEncoder.encode"); encoder.encode(decoded2); console.timeEnd("TextEncoder.encode"); ``` On macOS arm64 in Bun v0.4.1: ``` [0.69ms] TextDecoder.decode [0.54ms] TextDecoder.decode [0.59ms] TextDecoder.decode [0.21ms] TextEncoder.encode [0.20ms] TextEncoder.encode [0.25ms] TextEncoder.encode ``` Safari Technology Preview: ``` TextDecoder.decode: 0.621ms TextDecoder.decode: 0.589ms TextDecoder.decode: 0.604ms TextEncoder.encode: 2.317ms TextEncoder.encode: 1.945ms TextEncoder.encode: 1.966ms ``` For non-ascii UTF-8 input, TextEncoder.encode runs about 8x faster in Bun compared to Safari and that's mostly because it's using simdutf.
Attachments
Radar WebKit Bug Importer
Comment 1 2023-01-11 16:39:41 PST
Yusuke Suzuki
Comment 2 2023-02-11 17:37:44 PST
EWS
Comment 3 2024-07-16 12:01:11 PDT
Committed 281011@main (68eced08c0e3): <https://commits.webkit.org/281011@main> Reviewed commits have been landed. Closing PR #9990 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.