adraffy / ens-normalize.js

ENSIP-15 in JS
https://adraffy.github.io/ens-normalize.js/test/resolver.html
MIT License
63 stars 17 forks source link

Synchronously importing the module causes perf heavy side-effects to run #24

Closed jxom closed 9 months ago

jxom commented 10 months ago

It seems when I synchronously import @adraffy/ens-normalize, it causes some preparation side-effects to run: https://github.com/adraffy/ens-normalize.js/blob/main/src/lib.js#L172

This causes a pretty large performance hit (especially on webpages for first load time).

Wonder if it could be possible to instead export the init function so folks can choose to eagerly initialize/prepare, and if it hasn't been prepared at time of fn call (e.g. normalize_ens) then run init?

adraffy commented 10 months ago

Ah, oops, that init() is not supposed to be there. The new 1.10 release should have on-demand loading as you describe. I'll fix this before I release the final 1.10 update with the Unicode 15.1.0 changes (sometime before end of week.)

jxom commented 10 months ago

Thank you!

adraffy commented 10 months ago

The latest npm release 1.10.0 has the delayed init feature.

I investigated the init code a bit and made a few minor optimizations. I'm seeing about ~200ms on weak hardware. If this is still an issue, this can be significantly faster with a different data structure. Additionally, the init could be delayed for specific ASCII input.

adraffy commented 9 months ago

I was able to reduce it down to about 140ms on the same hardware. With a Set that uses intervals, it's under 100ms. I'll revisit this when I push the next round of compression changes.