Skip to content

Conversation

bakkot
Copy link
Collaborator

@bakkot bakkot commented Jan 7, 2024

Split out out from #33.

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

@syg
Copy link

syg commented Feb 7, 2024

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.

@jridgewell
Copy link
Member

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.

@bakkot bakkot mentioned this pull request Mar 14, 2024
@bakkot bakkot marked this pull request as draft August 8, 2024 22:26
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.

3 participants