olivernn / lunr.js

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

Improve the performance of Index.add. #208

Closed d0ugal closed 8 years ago

d0ugal commented 8 years ago

The loops in Index.add can easily be called hundreds of thousands of times for large documents. Larger documents can perform particularly badly1 under Chrome. Removing the usage of reduce and filter in favour of inline native for loops can lead to a 20-30% performance increase in Chrome. Firefox also sees a similar but much smaller impovement (~5%).

d0ugal commented 8 years ago

Would it be useful for me to create a jsperf test for this (as #163 did) or are the included benchmarks good enough?

The new benchmark I added isn't ideal since it causes GitHub to hide the diff. I'd be happy to do this any other way if you have any suggestions. Perhaps the test data needs to be moved to a JSON file.

olivernn commented 8 years ago

Thanks for taking a look at this, from the tests I did there was a significant performance improvement, which is always great!

I think that the new benchmark is fine for now, having the fixture in a separate file might make browsing the tests etc easier but its no show stopper.

I've included your change in the latest version, let me know if you have any issues, and thanks again for your help, much appreciated!

d0ugal commented 8 years ago

Thanks very much!