cfinke / Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
Other
501 stars 110 forks source link

Zero-copy loading of precomputed dictionaries #65

Open dennisss opened 6 years ago

dennisss commented 6 years ago

Why?

Wanted a way to avoid the browser frozen for half a second or more while loading the dictionary

How

Limitations

Other things fixed:

Benchmarks

TLDR: Loading from the precomputed dictionary table is magnitudes better in terms of memory usage and load time. But, checking and suggesting operations are much slower. From my tests, more performance could probably be obtained by optimizing the new datastructure, but so far it has been sufficient for interactive applications.

Memory usage taken manually by idling the following script:

var t = require('.'); var d = new t(); d.loadPrecomputed('en_US'); // d.load('en_US')

setTimeout(function(){ console.log('done!') }, 1000000)

Overall node process memory usage:

Using loadPrecomputed: 14.8Mb Using load: 59.9Mb

Speed

Generated by the bin/benchmark.js script.

Dictionary load time

  • regular 0.302s
  • precomputed 0.022s

dict.check() speed

  • hypersensitiveness (reg) 0.178s
  • hypersensitiveness (pre) 2.051s
  • Abbott's (reg) 0.114s
  • Abbott's (pre) 0.916s
  • 9th (reg) 0.147s
  • 9th (pre) 0.994s
  • aaraara (reg) 0.299s
  • aaraara (pre) 0.957s
  • didn't (reg) 0.11s
  • didn't (pre) 0.804s
  • he're (reg) 0.277s
  • he're (pre) 0.914s
cfinke commented 6 years ago

I'm fully in support of this idea. A few questions first though:

  1. Is it fully backwards compatible? If this change were merged and every single person using Typo started using it, would they have to change anything?

  2. Are you able to split any changes from "Other things fixed" into their own pull requests?

Thanks,

Chris