You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Large search indexes can cause Lunr to freeze the page while it creates the index. #859
When using readthedocs theme, search shows "no results" for a few seconds while search is being performed, and then results are loaded. However, few seconds are enough to convince the users nothing is found, and they move on.
changed the title [-]Search shows "No results" for a few seconds before results are loaded[/-][+]Search shows "Sorry, page not found" for a few seconds before results are loaded[/+]on Mar 3, 2016
Perhaps an indicator of search in progress can be added?
That seems reasonable to me. Presumably the problem occurs due to the large number of pages. On a smaller site, this would not be a problem as the wait time would be much less.
We have 50 files with 18,936 lines of Markdown. I don't know if that's considered large, but even for smaller projects running on slower servers it would provide a better user experience. Thanks for looking into it!
It appears that the RTD theme includes the default content "Sorry, page not found." on the search results page (see search.html#L18). However, the search tool will also replace any content with <p>No results found</p> (see search.js#L63) which makes the initial filler redundant. It appears that RTD displays nothing. Should we do the same or display a message to wait for results?
This is quite interesting. I assumed the delay was the length of time it takes to download the search index (about 0.5mb). However, there is a long delay after it is downloaded. So is the delay while lunr.js is processing the index? Meaning the slowness is probably more dependant users machines than the server. Looking a the Lunr change log there are a few performance improvements in 0.5.8 and later (we ship 0.5.7). So I think there are two things we should do:
Add a loading indicator (this could just be static text saying "Searching...") and remove the incorrect text in ReadTheDocs's search.html
I just cloned and tested with the DataTorrent docs locally, which confirms the slowness is with the JavaScript as downloading is almost instantaneous.
Even worse, my browser (Chrome) is locked up by the JavaScript for a good few seconds, so I can't actually click anything. I done some very rough measurements to try and find what was making it so slow. My timings below are all rounded because I don't have confidence in my measuring.
The loading of the JSON into Lunr is the culprit. This for loop takes around 8(!!) seconds. More specifically it is the call to index.add(doc), so I timed that for each document (the project has 1022, as we add individual markdown documents and page headers individually to improve the search results). Most of them are very fast (less than 50ms) but two are really slow. The Application Developer Guide takes around 1 second consistently and the Release Notes take around 4.5 seconds consistently.
I don't have time to keep looking now, but we need try and determine what makes these so slow. Is it just because these are long pages? Is there something that causes an issue with Lunr? I tested with both Lunr 0.5.7 and 0.6.0 and got similar results. 0.6.0 might actually be a little slower, but I didn't do enough tests to be confident about that.
Even worse, my browser (Chrome) is locked up by the JavaScript for a good few seconds, so I can't actually click anything.
I noticed the same behavior when looking into this as well. Although I didn't big any deeper. The point is that I can confirm this behavior is not isolated.
Add a loading indicator (this could just be static text saying "Searching...") and remove the incorrect text in ReadTheDocs's search.html
I don't see any reason why we can't do this now. I'll push a PR when I get a few minutes unless someone beats me to it.
I've pushed @d0ugal's changes in 0.7.0 of lunr, so there should hopefully be some improvements from that change.
Without knowing anything of how mkdocs makes use of lunr, I have a few suggestions that could improve the performance and user experience further:
Pre-build the index and then load this pre-built index
Move searching/building over to a webworker
As an example, the example lunr app makes use loading a pre-built index. I think a member of the Angular.js team wrote up how they improved performance using web workers too.
Reacted by Waylan Limberg, Jesse Sutherland, Mikey Lombardi (He/Him) and Mykola Golubyev
changed the title [-]Search shows "Sorry, page not found" for a few seconds before results are loaded[/-][+]Large search indexes can cause Lunr to freeze the page while it creates the index.[/+]on Mar 9, 2016
@waylan completely agree that pre-building is the best option here. Was just saying that there is nothing in lunr preventing a serialised index being stored client side. The tradeoff made with pre-building the index and serving it to the client is that, even gzipped, it can be quite large. That said, if it was me, I'd still opt for serving a pre-built index.
If there is anything I can help with from lunr then please do let me know, I'm more than happy to help.
If there is anything I can help with from lunr then please do let me know, I'm more than happy to help.
What would be ideal is a Python library that builds the index. Requiring our users to have both Python and Node installed is a little much (our Python script calls out to a Node script to build the index). As it happens, many users have both installed anyway, but I'm not comfortable making it a hard requirement and having the fallback results in two very different user experiences. Of course, I don't expect you to go build a Python clone of your JavaScript lib, but a publicly published spec of your index file format could go a long way toward someone else creating a Python lib (or Ruby, or ... whatever other language static site generators are written in).
This is similar to an approach I am hoping to move towards with a new version of lunr, documenting (JSON Schema?) the serialisation format would open up the possibility of using the JavaScript version as a client, with the actual indexing etc being done in any other language that can generate the serialised index. Python would probably be an excellent choice for this given the number of NLP and IR libraries available.
My Python is non-existent, so I'm unlikely to be able to produce anything production ready myself, but by documenting the format others could certainly produce an implementation that would be easier to integrate into MkDocs (or other tools).
Just a note: This may be a perfect case for requestIdleCallback - processing in the background without freezing the UI. I will think about including this into Material. Reasonable polyfills available.
Activity
[-]Search shows "No results" for a few seconds before results are loaded[/-][+]Search shows "Sorry, page not found" for a few seconds before results are loaded[/+]waylan commentedon Mar 3, 2016
That seems reasonable to me. Presumably the problem occurs due to the large number of pages. On a smaller site, this would not be a problem as the wait time would be much less.
sashadt commentedon Mar 3, 2016
We have 50 files with 18,936 lines of Markdown. I don't know if that's considered large, but even for smaller projects running on slower servers it would provide a better user experience. Thanks for looking into it!
waylan commentedon Mar 4, 2016
It appears that the RTD theme includes the default content "Sorry, page not found." on the search results page (see search.html#L18). However, the search tool will also replace any content with
<p>No results found</p>(see search.js#L63) which makes the initial filler redundant. It appears that RTD displays nothing. Should we do the same or display a message to wait for results?d0ugal commentedon Mar 4, 2016
This is quite interesting. I assumed the delay was the length of time it takes to download the search index (about 0.5mb). However, there is a long delay after it is downloaded. So is the delay while lunr.js is processing the index? Meaning the slowness is probably more dependant users machines than the server. Looking a the Lunr change log there are a few performance improvements in
0.5.8and later (we ship0.5.7). So I think there are two things we should do:0.6.0d0ugal commentedon Mar 4, 2016
I just cloned and tested with the DataTorrent docs locally, which confirms the slowness is with the JavaScript as downloading is almost instantaneous.
Even worse, my browser (Chrome) is locked up by the JavaScript for a good few seconds, so I can't actually click anything. I done some very rough measurements to try and find what was making it so slow. My timings below are all rounded because I don't have confidence in my measuring.
The loading of the JSON into Lunr is the culprit. This for loop takes around 8(!!) seconds. More specifically it is the call to
index.add(doc), so I timed that for each document (the project has 1022, as we add individual markdown documents and page headers individually to improve the search results). Most of them are very fast (less than 50ms) but two are really slow. The Application Developer Guide takes around 1 second consistently and the Release Notes take around 4.5 seconds consistently.I don't have time to keep looking now, but we need try and determine what makes these so slow. Is it just because these are long pages? Is there something that causes an issue with Lunr? I tested with both Lunr 0.5.7 and 0.6.0 and got similar results. 0.6.0 might actually be a little slower, but I didn't do enough tests to be confident about that.
waylan commentedon Mar 4, 2016
I noticed the same behavior when looking into this as well. Although I didn't big any deeper. The point is that I can confirm this behavior is not isolated.
I don't see any reason why we can't do this now. I'll push a PR when I get a few minutes unless someone beats me to it.
Update default text when search is running.
Improve the performance of Index.add.
d0ugal commentedon Mar 6, 2016
I investigated further. FireFox is much faster than Chrome. I managed to improve the performance under Chrome a bit. See: olivernn/lunr.js#208
Improve the performance of Index.add.
olivernn commentedon Mar 8, 2016
I've pushed @d0ugal's changes in 0.7.0 of lunr, so there should hopefully be some improvements from that change.
Without knowing anything of how mkdocs makes use of lunr, I have a few suggestions that could improve the performance and user experience further:
loadthis pre-built indexAs an example, the example lunr app makes use loading a pre-built index. I think a member of the Angular.js team wrote up how they improved performance using web workers too.
Upgrade to Lunr.js 0.7
[-]Search shows "Sorry, page not found" for a few seconds before results are loaded[/-][+]Large search indexes can cause Lunr to freeze the page while it creates the index.[/+]45 remaining items
olivernn commentedon Oct 3, 2016
@waylan completely agree that pre-building is the best option here. Was just saying that there is nothing in lunr preventing a serialised index being stored client side. The tradeoff made with pre-building the index and serving it to the client is that, even gzipped, it can be quite large. That said, if it was me, I'd still opt for serving a pre-built index.
If there is anything I can help with from lunr then please do let me know, I'm more than happy to help.
waylan commentedon Oct 3, 2016
What would be ideal is a Python library that builds the index. Requiring our users to have both Python and Node installed is a little much (our Python script calls out to a Node script to build the index). As it happens, many users have both installed anyway, but I'm not comfortable making it a hard requirement and having the fallback results in two very different user experiences. Of course, I don't expect you to go build a Python clone of your JavaScript lib, but a publicly published spec of your index file format could go a long way toward someone else creating a Python lib (or Ruby, or ... whatever other language static site generators are written in).
olivernn commentedon Oct 3, 2016
This is similar to an approach I am hoping to move towards with a new version of lunr, documenting (JSON Schema?) the serialisation format would open up the possibility of using the JavaScript version as a client, with the actual indexing etc being done in any other language that can generate the serialised index. Python would probably be an excellent choice for this given the number of NLP and IR libraries available.
My Python is non-existent, so I'm unlikely to be able to produce anything production ready myself, but by documenting the format others could certainly produce an implementation that would be easier to integrate into MkDocs (or other tools).
Optimize search by building index locally.
Optimize search by building index locally.
squidfunk commentedon Oct 22, 2017
Just a note: This may be a perfect case for
requestIdleCallback- processing in the background without freezing the UI. I will think about including this into Material. Reasonable polyfills available.Implement fallback for no worker support
Implement fallback for no worker support
waylan commentedon Feb 28, 2018
FYI to everyone following this: A refactor of search is available for review in #1418 which addresses all of the concerns raised here and more.
Refactor search plugin (#1418)
Improve the performance of Index.add.
Improve the performance of Index.add.