Repository navigation
Copy only referenced highlight.js assets into built sites - #90
Merged
Merged
Conversation
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.
Contributor
Merging this PR will improve performance by 14.02%
Performance Changes
Tip Curious why this is faster? 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.
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_themenow 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 whenhighlightjsis enabledhljs_style/hljs_style_darkhljs_languageshighlight/whenhighlightjs: falseFiles resolving to a
custom_diror 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:
indexing: titlesis configured, where the parse result was never used (identical index output)AGENTS.mdgains a "Referencing the Upstream Project" policy sectionNo-regression verification
hljs_languages/hljs_style,highlightjs: false, readthedocs theme): every remaining file is byte-identical (sole exception: the theme's embeddedBuild Date UTCtimestamp); removals are 100% underhighlight/; configured languages/styles are all present.mainin this container).highlightjs: false, and the custom_dir protection.mkdocs build --strictof this repo's own docs passes and correctly ships its configureddjango/yamlgrammars.Measured impact (local wall time)
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
docs/about/release-notes.mdupdated (if applicable)🤖 Generated with Claude Code
https://claude.ai/code/session_018Hw7x9BxxpuKiLkzjLczp9