mapbox / pbf

A low-level, lightweight protocol buffers implementation in JavaScript.
BSD 3-Clause "New" or "Revised" License
801 stars 107 forks source link

Fix utf8 read peformance #109

Closed ahk closed 5 years ago

ahk commented 5 years ago

Currently readUtf8 is both slow in terms of ops/s and retains excessive amounts of memory when reading long strings (long being experimentally found to be more than 12 bytes).

This PR adds a heuristic to use the built-in browser TextDecoder API in the case of these long strings, which improves ops/s and also memory retention (avoids the usage of sophisticated concatenated string data structures based on trees of pointers).

Closes #106. cc @dcervelli