Performance issue with large list and long search text
See original GitHub issueI’m not sure am I doing something wrong, but I noticed that when doing search with a very long string and quite low threshold of 0.3, the search becomes very slow ~8-900ms with MBP 2015.
It’s hard for me to pinpoint exactly the cause, but since there isn’t issues searching with a short string, I guess the longer string just isn’t handled well by a computation, that isn’t exactly O(1).
That’s the lowest level where my Chrome JS profiler was able to get to. Doing simple performance check with:
console.time('search')
const newResults = fuse.search(newVal)
console.timeEnd('search')
confirms that this indeed is the culprit.
A value for newVal might be eg Ajoneuvot ja liikenne / Autot / Automerkit / Volkswagen / Bora, Vento ja Jett
. Fuse is provided a list, where the first searched value is string (similar to that previous one), the second the splitted version of that same string from ‘/’ eg ['Ajoneuvot ja liikenne', 'Autot', 'Automerkit', 'Volkswagen', 'Bora, Vento ja Jett']
. The options object being: {threshold: 0.3, keys: ['text', 'breadcrumb'], maxPatternLength: 32 }
.
My search items list is 2427 long, with a single instance being eg:
{
breadcrumb: ["Ajanviete"]
key: 52
text: "Ajanviete"
value: 52
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
I made a demo here https://teemukoivisto.github.io/search-demo-app/
Quite weirdly, it is much faster when I have Chrome’s developer tools hidden. Now it’s even usable on my Android. But it’s still laggy and the worst of all, when I have a specific topic chosen, topics close to it don’t show in sequential fashion.
Eg I have topic
Harrastukset / Pelit / Vedonlyönti ja rahapelit / Pokeri / Pokeriturnaukset
chosen, yet after first 10 or so items I start getting topics from way off the original egViihde ja kulttuuri / Kirjallisuus / Sarjakuvat / Omat sarjakuvat
. It should be showing topics from the same parent topic egHarrastukset / Pelit / Vedonlyönti ja rahapelit / Yleistä vedonlyönnistä
and work its way down. I added thetokenize: true
parameter but it didn’t help.I guess this means I have to make my own custom search. I had hoped I would avoid using dull substring search but I guess I have to make use of it. Maybe use only fuzzy search for the last 10 characters of the string.
I am facing the same issue as on my React Native app. There are 2k items and the performance significantly dropped when the search text was growing from 1 to 100 chars.
Setting the
threshold
to lower value (lower fuzziness) would help a bit.