items fall out of the cache after 4 seconds (why?)
we only keep 512 items
The latter is a big problem - if you type more than 512 words in your text box / app, performance starts to degrade fairly linearly because all but 512 lookups will always be cache misses. Given that we're just storing booleans, I think a cache size of ~5000 would be more reasonable and accommodate writing a whole email, for example!
On macOS, querying the native module for whether a word is misspelled is not free - in fact, it's pretty slow. Because of this, this module implements an LRU cache here: https://github.com/electron-userland/electron-spellchecker/blob/master/src/spell-check-handler.js#L130.
However:
The latter is a big problem - if you type more than 512 words in your text box / app, performance starts to degrade fairly linearly because all but 512 lookups will always be cache misses. Given that we're just storing booleans, I think a cache size of ~5000 would be more reasonable and accommodate writing a whole email, for example!