mkdocs-material icon indicating copy to clipboard operation
mkdocs-material copied to clipboard

Search: caching for faster startup

Open nnmm opened this issue 2 years ago • 4 comments

Context

In our docs, it takes about 5 seconds for the search plugin to become ready.

Description

Currently, the search index input is requested and indexed on every page load. Instead, the final search index could be kept in local browser storage and loaded from there if the search index input can be determined to be the same.

Related links

  • https://github.com/squidfunk/mkdocs-material/issues/2976

Use Cases

The user would need to provide a version identifier (e.g. git SHA, release number) that will be used as the cache key. Alternatively, material could compute a hash of the docs itself, though I'm not sure how realistic that is.

The advantages would be reduced bandwidth usage and less delay until the search plugin is ready.

Visuals

No response

Before submitting

nnmm avatar Apr 19 '23 13:04 nnmm

Thanks for suggesting! We're currently reworking the search implementation to be much more powerful that what we currently have in place. Caching is something we'll also be investigating. In the meantime, you can use instant loading, which means you will only pay the cost of index initialization on the first request.

squidfunk avatar Apr 19 '23 16:04 squidfunk

If I understand #2976 correctly, the prebuilt search index will be removed in the next iteration of the search functionality.

One of the strengths of Material for MkDocs thus far has been its support for offline usage.

Will the caching mechanism proposed here (or the instant loading workaround) support the offline use case with the new search features?

infotexture avatar May 05 '23 20:05 infotexture

The prebuilt index was removed in Material for MkDocs 8 1,5 years ago. Offline search already works pretty well, and the new search will definitely continue to do so. We'll investigate caching on file:// locations, but I think for most docs, it won't be necessary, as the new search needs a fraction of the time to create the search index. My tests show that the new search index builds up to 5x faster, i.e., for our docs, the time dropped from 200ms to 40ms.

Instant loading does not work on file:// due to browser limitations. Same goes for some other features.

squidfunk avatar May 06 '23 05:05 squidfunk

Please see the announcement in #6307.

squidfunk avatar Nov 07 '23 14:11 squidfunk