Skip to content

Reuse Markdown conversions between serve rebuilds - #131

Merged
shenxianpeng merged 1 commit into
mainfrom
claude/project-thread-8gce4u
Nov 1, 2026
Merged

shenxianpeng merged 1 commit into
mainfrom
claude/project-thread-8gce4u

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Every rebuild of mkdocs serve converts every page from Markdown to HTML again, although usually only one file changed. Markdown conversion is about a third of a rebuild.

While the server runs, this keeps each page's converted HTML, table of contents, title, anchors and logged warnings, keyed by:

  • the page's Markdown after on_page_markdown,
  • the Markdown extensions and their config (functions in the config by their import path),
  • the page's source path and URL,
  • every file of the site (path, URL, inclusion, whether it is a page), use_directory_urls and the validation settings,
  • the MkDocs NG version.

When all of these match, the earlier result is reused and its warnings are logged again, so strict mode and the console output stay the same. All plugin events still run for every page, with the same values. Entries a rebuild didn't use are dropped at the next rebuild.

The cache is only used when every extension is on a list of extensions whose output depends only on their input: Python-Markdown's own and most of PyMdown Extensions, plus Material's emoji. pymdownx.snippets and pymdownx.b64 read other files and are left out. Extensions that plugins add as instances (mkdocstrings, mkdocs-autorefs, which record anchors while converting) turn it off, so those sites rebuild exactly as before. mkdocs build doesn't use the cache.

Numbers

Real mkdocs serve, 400-page benchmark corpus with Material for MkDocs, edit one page: rebuild 7.6s → 4.0s. With the mkdocs theme, in-process rebuild 4.9s → 2.2s. A new test_serve_rebuild CodSpeed benchmark covers this loop.

Checks

  • Unit tests: reuse, changed Markdown, changed file list, changed config, warnings logged again, unknown extensions and extension instances turning it off, pruning, inactive outside serve.
  • Whole-site test: builds with no cache, a cold cache and a warm cache give identical HTML and identical warnings, with no conversion on the warm build.
  • The full test suite also passes with the cache forced on and never cleared, and so does the 32-plugin compatibility matrix (including mkdocs-static-i18n, which renders pages once per language).
  • Real mkdocs serve: the edit shows up after the rebuild.

Release notes under 1.11.0 and a note for plugin authors in the plugin guide.

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

@shenxianpeng shenxianpeng self-assigned this Nov 1, 2026
@codspeed

codspeed Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 28 untouched benchmarks
🆕 1 new benchmark

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_serve_rebuild N/A 1.7 s N/A

Comparing claude/project-thread-8gce4u (eb816e0) with main (2283319)

Open in CodSpeed

Every rebuild of mkdocs serve converted every page from Markdown to HTML
again, although usually only one file changed. Keep the converted HTML,
table of contents, anchors and logged warnings of each page while the
server runs, and reuse them when the page's Markdown (after
on_page_markdown), the extensions and their config, the page URL and the
site's files are unchanged. Warnings are logged again, so strict mode and
the console behave as before. Plugin events still run for every page.

The cache is only used when every Markdown extension is on a list of
extensions known to depend on nothing else; snippets, b64 and extensions
that plugins add as instances (mkdocstrings, autorefs) turn it off.

400 pages with Material: rebuild 7.6s -> 4.0s.
@shenxianpeng
shenxianpeng force-pushed the claude/project-thread-8gce4u branch from b156939 to eb816e0 Compare November 1, 2026 13:10
@shenxianpeng
shenxianpeng merged commit d20e77b into main Nov 1, 2026
24 checks passed
@shenxianpeng
shenxianpeng deleted the claude/project-thread-8gce4u branch November 1, 2026 13:28
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