Skip to content

Keep the serve cache when a page is added or removed - #152

Merged
shenxianpeng merged 1 commit into
mainfrom
claude/project-thread-epdfwi
Nov 2, 2026
Merged

shenxianpeng merged 1 commit into
mainfrom
claude/project-thread-epdfwi

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

The Markdown cache of mkdocs serve (#131) keyed every page on the whole list of site files. So adding, removing or renaming any page made every page convert from Markdown again: 7–12 seconds on a 1,000-page site, compared with about 2 seconds for an edit.

A page's conversion only uses the other files through the link lookups (Files.get_file_from_path) in _RelativePathTreeprocessor, including the "Did you mean…" guesses. The cache now records those lookups and what each one found (the file's URL and inclusion). An entry is reused only while every lookup still finds the same thing. The page's own inclusion is now part of the key, because it changes warning levels.

Serve rebuild times on a 1,000-page site (4 cores):

before after
mkdocs theme, add a page 7.4 s 2.2 s
mkdocs theme, delete it 8.1 s 2.6 s
Material, add a page 10.9 s 5.7 s
Material, delete it 12.2 s 6.7 s
edit a page (unchanged) 1.7 / 5.2 s 1.7 / 5.5 s

I also checked the result on that site: after adding a page that an existing page already linked to, the serve output is the same as a clean build, except for the build date.

Related Issue

Follow-up to #131 and #145.

Checklist

  • New tests added for new behavior (unrelated files keep the cache; a removed or moved link target, or a new "Did you mean" suggestion, converts the page again)
  • Documentation updated (dev-guide/plugins.md note on the cache)
  • Release notes docs/about/release-notes.md updated (new "1.11.0 (unreleased)" section)

The Markdown cache of `mkdocs serve` keyed every page on the whole list of
site files, so adding, removing or renaming any page converted every page
again. A page's conversion only uses the files that its links look up, so
record those lookups and reuse the HTML while they find the same files.

With 1,000 pages, a new page shows up after 2.2 s instead of 7.4 s with the
mkdocs theme, and after 5.7 s instead of 10.9 s with Material.
@shenxianpeng shenxianpeng self-assigned this Nov 2, 2026
@codspeed

codspeed Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 23.4%

⚡ 1 improved benchmark
✅ 28 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_get_yaml_loader 398.9 µs 323.2 µs +23.4%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/project-thread-epdfwi (dd9d9e7) with main (0ff260b)

Open in CodSpeed

@shenxianpeng
shenxianpeng merged commit 7072ea6 into main Nov 2, 2026
30 of 31 checks passed
@shenxianpeng
shenxianpeng deleted the claude/project-thread-epdfwi branch November 2, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant