Skip to content

Large search indexes can cause Lunr to freeze the page while it creates the index. #859

Closed

Description

@sashadt

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.

For example see: http://docs.datatorrent.com Try searching for "test" and you will see the following for a while:

image

Perhaps an indicator of search in progress can be added?

Activity

  1. 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
  2. waylan commented on Mar 3, 2016

    @waylan
    Contributor

    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.

  3. sashadt commented on Mar 3, 2016

    @sashadt
    Author

    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!

  4. waylan commented on Mar 4, 2016

    @waylan
    Contributor

    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?

  5. d0ugal commented on Mar 4, 2016

    @d0ugal
    Contributor

    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
    • Update Lunr.js to 0.6.0
  6. d0ugal commented on Mar 4, 2016

    @d0ugal
    Contributor

    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.

  7. waylan commented on Mar 4, 2016

    @waylan
    Contributor

    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.

  8. added a commit that references this issue on Mar 4, 2016
  9. d0ugal commented on Mar 6, 2016

    @d0ugal
    Contributor

    I investigated further. FireFox is much faster than Chrome. I managed to improve the performance under Chrome a bit. See: olivernn/lunr.js#208

  10. added a commit that references this issue on Mar 8, 2016
  11. olivernn commented on Mar 8, 2016

    @olivernn

    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.

  12. added a commit that references this issue on Mar 9, 2016
  13. 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
  14. 45 remaining items

  15. olivernn commented on Oct 3, 2016

    @olivernn

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

  16. waylan commented on Oct 3, 2016

    @waylan
    Contributor

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

  17. olivernn commented on Oct 3, 2016

    @olivernn

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

  18. self-assigned this
    on Dec 2, 2016
  19. squidfunk commented on Oct 22, 2017

    @squidfunk
    Contributor

    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.

  20. waylan commented on Feb 28, 2018

    @waylan
    Contributor

    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.

  21. added a commit that references this issue on Mar 6, 2018
    dd7e2d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions