mathiasbynens / punycode.js

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891.
https://mths.be/punycode
MIT License
1.6k stars 159 forks source link

Improve V8-specific performance #49

Open mathiasbynens opened 8 years ago

mathiasbynens commented 8 years ago

@bnoordhuis posted some excellent ideas here:

For example, .toASCII() calls String#split() twice and is heavy on the map-over-substrings idiom. It would probably be faster to:

  1. Scan for the split character and only split when found; saves allocating an array in the common case.
  2. Iterate rather than map; V8 is not great at lowering/inlining callbacks.
  3. Try to avoid concatenating strings too much; cons strings eventually have to be flattened.

There is probably more but that is what stood out from a quick look.

Patches welcome.

cc @trevnorris