Skip to content

Copy only referenced highlight.js assets into built sites - #90

Merged
shenxianpeng merged 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse
Aug 12, 2026
Merged

shenxianpeng merged 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

First optimization PR on top of the CodSpeed baseline (#88/#89), targeting the largest safe win found by profiling the build pipeline.

The finding

Profiling a 204-page build showed static-file copying at ~10% of a clean build — and 444 of the 472 copied files were the complete highlight.js distribution (192 language grammars + ~250 styles) bundled into each built-in theme by the (unreleased) #75, of which a site only ever references the handful selected by its configuration. On small sites this fixed cost dominated: roughly half the build time of a 10-page site was spent copying grammar files nothing loads.

The change

Files.add_files_from_theme now skips built-in-theme highlight.js assets that the theme configuration doesn't reference:

  • highlight.min.js (and the styles-directory images that some classic styles reference) are copied when highlightjs is enabled
  • only the styles selected by hljs_style / hljs_style_dark
  • only the languages listed in hljs_languages
  • nothing under highlight/ when highlightjs: false

Files resolving to a custom_dir or to a third-party theme are never filtered, so overrides keep working unchanged (covered by a dedicated test). Since the bundled highlight.js only exists in the unreleased 1.8.0 line (#75), no released configuration observes any change.

Also included:

  • the search plugin now skips the whole-page HTML parse when indexing: titles is configured, where the parse result was never used (identical index output)
  • AGENTS.md gains a "Referencing the Upstream Project" policy section

No-regression verification

  • Byte-level site comparison before/after for four scenarios (mkdocs theme default, custom hljs_languages/hljs_style, highlightjs: false, readthedocs theme): every remaining file is byte-identical (sole exception: the theme's embedded Build Date UTC timestamp); removals are 100% under highlight/; configured languages/styles are all present.
  • Full unit suite passes (759 tests; the only failures are the 4 pre-existing localization environment failures also present on main in this container).
  • New tests cover: default style selection, configured languages/styles, highlightjs: false, and the custom_dir protection.
  • mkdocs build --strict of this repo's own docs passes and correctly ships its configured django/yaml grammars.

Measured impact (local wall time)

Benchmark Before After
full build, 10 pages 200 ms 172 ms (−14%)
full build, 200 pages 2.99 s 2.54 s (−15%)
files copied per site (mkdocs theme, defaults) 512 74

Built sites also shrink by ~440 files / ~2 MB — less deploy upload, less hosting clutter. The CodSpeed run on this PR gives the deterministic numbers.

Related Issue

Part of the build/serve performance work tracked in #59 (item 2); right-sizes the unreleased #75.

Checklist

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

🤖 Generated with Claude Code

https://claude.ai/code/session_018Hw7x9BxxpuKiLkzjLczp9

Profiling a 204-page build showed that copying static theme files
accounted for ~10% of a clean build - and 444 of the 472 copied files
were the complete highlight.js distribution (192 language grammars and
~250 styles) bundled into the built-in themes, of which a site only
ever references the assets selected by its configuration.

The built-in themes now copy only what their templates actually load:

* highlight.min.js (plus styles-directory images) when highlightjs is
  enabled
* the styles selected by hljs_style and hljs_style_dark
* the languages listed in hljs_languages
* nothing under highlight/ when highlightjs is disabled

Files that resolve to a theme custom_dir or to a third-party theme are
never filtered, so overrides keep working unchanged. Since the bundled
highlight.js shipped only in the not-yet-released 1.8.0 (#75), no
released configuration is affected.

Also skip the whole-page HTML parse in the search plugin when
'indexing: titles' is configured, where the parse result was never
used.

Verified by byte-comparing built sites before/after for both built-in
themes, with custom hljs settings and with highlightjs disabled: all
remaining files are identical; only unused highlight/ assets are
dropped (438-444 files fewer per site). Clean-build wall time at 200
pages improves by roughly 15%; small sites gain the most since the
copying was a fixed cost.
@codspeed

codspeed Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 14.02%

⚡ 2 improved benchmarks
✅ 26 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_full_build_scaling[10] 1.9 s 1.6 s +15.07%
⚡ test_dirty_rebuild 873 ms 772.7 ms +12.99%

Tip

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


Comparing claude/mkdocs-issue-4167-15dhse (cf4c57f) with main (e1f0031)

Open in CodSpeed

@shenxianpeng
shenxianpeng merged commit f8a66a0 into main Aug 12, 2026
23 checks passed
@shenxianpeng
shenxianpeng deleted the claude/mkdocs-issue-4167-15dhse branch August 12, 2026 15:38
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