proposal-arraybuffer-base64 icon indicating copy to clipboard operation
proposal-arraybuffer-base64 copied to clipboard

add outputOffset to the `into` methods

Open bakkot opened this issue 1 year ago • 2 comments

Split out out from https://github.com/tc39/proposal-arraybuffer-base64/pull/33.

Won't be in this proposal unless implementation or user feedback demonstrates need during stage 3.

bakkot avatar Jan 07 '24 23:01 bakkot

Some numbers, finally. From this: https://jsperf.app/qafule/12

Looks like about the following speedups from using an offset:

  • Chrome: 28% faster
  • Safari: 18% faster
  • Firefox: 31% faster

Microbenchmark, but those numbers mean this decision can affect performance on the hot path.

syg avatar Feb 07 '24 23:02 syg

I made another micro benchmark (one using TextEncoder.encodeInto()) that shows an even more stark improvement.

  • Using a write-offset and str.substring() is:
    • Chrome: 53% faster
    • Firefox: 138% faster
    • Safari: 71% faster
  • Using a write-offset and read-offset:
    • Chrome: 16% faster (?)
    • Firefox: 158% faster
    • Safari: 122% faster

For fun, I also threw in an attempt to use premade subarrays to use with TextEncoder.encodeInto. Doing so is also considerably faster than creating subarrays on-the-fly:

  • Chrome: 37% faster
  • Firefox: 49% faster
  • Safari: 29% faster

I don't know if it's expensive to create subarrays, or if it's the GC pressure, but subarrays suck.

jridgewell avatar Feb 08 '24 07:02 jridgewell