hzoo / babel-plugin-dedupe-string-literals

Dedupe strings with new variable declarations.
12 stars 4 forks source link

Improve performance? #5

Open mathiasbynens opened 8 years ago

mathiasbynens commented 8 years ago

Understandably this tool is slow for large files such as https://raw.githubusercontent.com/mathiasbynens/unicode-8.0.0/15228776965be9ef1af995403b7d47386607318c/bidi-classes/index.js (over 6 MB).

One idea is to use a Map rather than a plain object for the cache, which should result in faster lookups. https://github.com/hzoo/babel-plugin-dedupe-string-literals/blob/59db33128a7d9a1f7e09970b69b5346c9673c132/src/index.js#L7 Of course, this assumes the Map usage isn’t transpiled away before publishing to npm. (Node.js v0.12.14+ supports Map; personally I only care about Node.js v6 support since that’s what I use in my build environment.)

hzoo commented 8 years ago

Yeah I was thinking that too, and right now the key lookup is the value of the string itself

This was mainly for your use case anyway so why not.

We can use package.json engines with Map/Set + make a 2.0

mathiasbynens commented 8 years ago

and right now the key lookup is the value of the string itself

I think this is fine now that we use Map. Hashing before the lookup would only make it slower, no?

hzoo commented 8 years ago

Yeah 👍