Closed samuelgozi closed 6 months ago
index.browser.js
. You need to fix it first.index.js
which has different optimizations.Tested on latest version:
Chrome
Old 1634ms
New 1245ms
Safari
Old 1208ms
New 760ms
Firefox
Old 1207ms
New 742ms
Browser support doesn't change at all. I will update the source file.
I now updated the right place.
Ok i will fix everything you mentioned. In regards to the use of the string inside the function, I don't think we should hoist it manually since I didn't see any effect on performance, but I do think that this way it looks nicer.
Maybe I should remove the comment instead since it not important
OK, let's keep string as is. I will do some optimizations later for smaller bundle size.
Done. Package size limit has exceeded by 34 B
Package size limit has exceeded by 34 B
Try to import alphabet from https://github.com/ai/nanoid/blob/main/url-alphabet/index.js
We have a fun hack there, we put the same letters not in alhabetical order, but in order for better gzip.
And please update packge→size-limit
for new size (so we will track size changes by commit).
Package size limit has exceeded by 15 B
TIL, very cool!
Made the changes
I also reduced 8 bytes by reusing size
variable 4db3464
Using the while loop is actually a little bit faster. Very nice idea!
I know this is a lazy PR since I didn't check other files to make sure I'm making the correct changes, so I'm sorry about that. This implementation is much faster. The benchmark checks the time to generate one million nanoids.
I hope you find it useful 🙏