Fuse.js is already plenty fast but I wanted to identify further opportunites for optimisation as I (slowly) add more words to the dictionary. (And why not make the app as efficient as possible anyway?)
So I ran a few simple tests on three desktop browsers. Each test does 300 searches (via the ‘choose a random word’ button) per browser per JS object literal and JSON file, the latter of which is 134 kB. The maximum number of possible values to check against in the dataset is 4,239.
The results, averaged across each of the six tests, are:
|Object-literal-to-JSON difference (a positive result means slower)||+2.578%||+10.526%||+3.669%|
So I was wrong in my hypothesis: searching the JSON is in fact slower, by as much as 10% in the case of Safari.
In terms of actually parsing larger amounts of data, this article pegs JSON as the winner, but the above tests show that for my use case — using Fuse.js to fuzzy-search a dataset with about 4,000 possible items to check against — object literals appear to be the way to go.
(There’s a CodeSandbox here with the actual results data.)