Skip to content

Conversation

@rvagg
Copy link
Owner

@rvagg rvagg commented Jan 21, 2026

Optimise fromString() thresholds based on benchmarking in today's standard runtimes:

  • Node.js (Buffer.from): change 64 to 24 chars
  • Browser (TextEncoder): change 64 to 200 chars

Buffer.from has low overhead, so use it for shorter strings. TextEncoder has high call overhead (~10-20x slower than manual utf8ToBytes for short strings), so only use it for long strings.

Node.js: +2-4% short string encode, +19-24% medium string encode
Browser: +17-63% encode improvement across string-heavy workloads

Optimise fromString() thresholds based on benchmarking in today's
standard runtimes:
- Node.js (Buffer.from): change 64 to 24 chars
- Browser (TextEncoder): change 64 to 200 chars

Buffer.from has low overhead, so use it for shorter strings.
TextEncoder has high call overhead (~10-20x slower than manual
utf8ToBytes for short strings), so only use it for long strings.

Node.js: +2-4% short string encode, +19-24% medium string encode
Browser: +17-63% encode improvement across string-heavy workloads
@rvagg rvagg merged commit ef1e62d into master Jan 21, 2026
16 checks passed
@rvagg rvagg deleted the rvagg/fromString-threshold branch January 21, 2026 02:01
@github-actions
Copy link

🎉 This PR is included in version 4.5.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants