Skip to content
Myr

Update index.browser.js (#144)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This isn't a huge gain, but ran across these while doing some other testing. In the browser version while loop, I believe there is an extra comparison `0 <`. Also, I've found using `+=` reduces performance ~4k-6k/sec. Showing improvements of ~10k-80k/sec depending on browser (needs more testing). #### Changes `index.browser.js` ```js // Original while (0 < size--) { id += url[bytes[size] & 63] } // Modified while (size--) { id = id + url[bytes[size] & 63] } ``` #### Benchmark Link **[View benchmarks on jsPerf](https://jsperf.com/nano-id-browser-optimizations/1)** #### Notes In the benchmarks link, I explored using modulo vs the bitwise `&` and caching the url string length into a variable. On average, the best combination across 3 browsers was removing the extra `0 <` comparison and replacing `+=` with explicit assignment.

authored by Stephen Richardson · committed by Andrey Sitnik · parent 84dc8e0 · Browse files · 1 file+2 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−2 removed

  • other:+2 added−2 removed

1 file+2 added−2 removed

modified:index.browser.js+2 added-2 removed