Skip to content
jamieonkeys.dev

Fuse.js: JSON vs JS object literal speed tests

Which is more efficient?

I’m building a Scots glossary app using Fuse.js as the fuzzy-search algorithm.

The data is currently in the form of a JavaScript object literal, and I wanted to check whether feeding Fuse JSON instead would result in faster searches (as I jaloused it might).

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:

ChromeSafariFirefox
Object literal2.527ms5.976ms6.77ms
JSON2.593ms6.64ms7.023ms
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.

As far as comparing the browsers, in these tests the Chrome V8 JavaScript engine performs about two-and-a-half times as fast as Safari and Firefox’s.

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.)