olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.91k stars 546 forks source link

pre-building indexes & Safari iOS #330

Open LorenzoSerino opened 6 years ago

LorenzoSerino commented 6 years ago

Hello olivernn, i report there is a problem using pre-building indexes on Safari iOS

iOS Resource Limits

  • JavaScript execution time limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, Safari on iOS stops executing the script at a random place in your code, so unintended consequences may result.

using the pre-building indexes with data dimension >= 1M : Safari stop the executing script and crashes.

The offending code line seems to be:

var idx = lunr.Index.load(JSON.parse(data))

in detail : JSON.parse(data) i try to verify the CPU time :

var t0 = performance.now();
JSON.parse(data)
var t1 = performance.now();
console.log("Call to JSON.parse(data) took " + (t1 - t0) + " milliseconds.")

and the CPU time is very higth in comparison to a simple object vector/map strings. The relationship is ten to one.

I think the problem is in floating point conversion but i'm not sure.

So i gave up of pre-building indexes.

olivernn commented 6 years ago

Thanks for reporting this, out of interest, how large is the serialised index that you are trying to load?

I've been thinking of providing a non JSON serialisation of the index, the original reason was to reduce the size of the index, but having some format that could be parsed in a way that is less expensive than JSON (or at least could pause to avoid these long executions) would be another benefit.

andrejpavlovic commented 5 years ago

Using something like Oboe.js helps prevent iOS from crashing, but then it takes 10 times longer to parse the index.