ashtuchkin / iconv-lite

Convert character encodings in pure javascript.
MIT License
3.08k stars 282 forks source link

First encode/decode is slow #220

Closed Zazama closed 5 years ago

Zazama commented 5 years ago

Hello, I'm experiencing a kinda strange issue. My first execution of .encode/.decode is always way slower than following calls.

Image

As you can see, I'm measuring the performance of an encode call that is looped. I've set a fixed string to make sure every string has the same length, but the issue also persists with variable/different strings. It also doesn't matter if it's a decode or encode call. I'm unsure of what is causing this and if it's an issue of iconv-lite or nodejs itself, so I wanted to ask if you have any ideas?

I'm using nodejs v10.15.3 and iconv-lite v0.5.0

ashtuchkin commented 5 years ago

That is expected. We only load encoding tables into memory on demand, on the first call to encode/decode. The tables are large and it takes ~15ms to load them, so we'd like to avoid this cost if the app is not actually using the conversion. Does it make sense?

Zazama commented 5 years ago

That makes sense, I just wasn't sure if it's intended, thank you!