Repository navigation
Cut the page cache's cost when pages change - #155
Merged
Merged
Conversation
After an edit, every rebuild rendered the theme template of every page, which took most of the rebuild time on large sites, since each page holds the whole navigation. Keep each page's HTML, keyed on a digest of its template context: every attribute of the page, the navigation with the titles, URLs and metadata of its pages, the list of pages, the config, the other context variables, the template files that were loaded and the Jinja globals. A page whose context holds anything without a stable description is rendered as before. The page_context and post_page events still run for every page; when there are no post_page events and the file already holds the HTML, the page is skipped right away. The HTML is kept compressed, about 16 KB per page with Material. With 1,000 pages, an edited page shows up after 0.9 s instead of 2.3 s with the mkdocs theme, and after about 1.4 s instead of 4.1 s with Material.
- Only cache page HTML when serve's site output is active: without it the build date changes every build, so no page could be reused. - Without post_page events, keep only the digest of the written file instead of a compressed copy of the HTML. - Build page keys with marshal instead of repr(), and import the types _stable() checks once. - Make the serve_rebuild benchmark set up the site output as serve does.
- Only cache page HTML when serve's site output is active: without it the build date changes every build, so no page could be reused. - Without post_page events, keep only the digest of the written file instead of a compressed copy of the HTML. - Build page keys with marshal instead of repr(), and import the types _stable() checks once. - Make the serve_rebuild benchmark set up the site output as serve does.
…to claude/project-thread-epdfwi # Conflicts: # docs/about/release-notes.md
Contributor
Merging this PR will improve performance by 44.81%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #154. CodSpeed flagged
test_serve_rebuildas 21% slower on #154. The benchmark doesn't set up serve's site output, so the build date changed on every build and no page could ever be reused. Every page then paid for the cache key and a zlib-compressed copy of its HTML and got nothing back. That cost also applies in real serve whenever pages miss, for example after a template edit.post_pageevents, only the digest of the written file is kept, not a compressed copy of the HTML. The file on disk is the cached copy, and if it changed the page is rendered again.marshal(version 2, which has no back-references, so equal values give equal bytes) instead ofrepr(), which is about 7× faster. The types_stable()checks are imported once.test_serve_rebuildnow sets up the site output the same waymkdocs servedoes, so the benchmark measures real serve.Measured on 200 benchmark pages, minimum of 5 rebuilds:
Related Issue
Follow-up to #154.
Checklist
docs/about/release-notes.mdupdated (if applicable). Already covered by the Reuse the HTML of unchanged pages in mkdocs serve #154 entry for 1.11.0.