[Infrastructure] Cache encoded images and minified HTML across builds - #45
Merged
Merged
Conversation
|
|
||
| import pytest | ||
|
|
||
| import nmteam_support.minify as minify |
Deploying nmteam-support with
|
| Latest commit: |
4c1d336
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e3054767.nmbot-telegram-doc.pages.dev |
| Branch Preview URL: | https://perf-build-pipeline.nmbot-telegram-doc.pages.dev |
agoudbg
approved these changes
Sep 16, 2026
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.
背景
build workflow 每次跑构建都在重新编码所有图片和页面,但大部分时候源文件根本没变过。
排查后发现
optimize_assets的增量判断是摆设:MkDocs 每次非 dirty 构建都会先把site/掀掉,上一轮的产物和判断依据被连带抹掉,于是每张图每次都重编码。WebP 压缩模块之前写死了最高压缩档
method=6,压缩时长暴增数倍,换来的却只有微不足道的 1.7% 体积缩减。改动
site/外面加一层内容寻址缓存,键由输入内容和变换参数一起算出。命中的栅格图和页面直接复制进site/,只有源文件或参数变了才重新编码。method从 6 降到 5;并发不再写死 4,改为CPU 核心数 -1(上限 8)。404.html不会被压缩。基准测试
pytest-benchmark,同一台机器两份 worktree 交替跑,取 min。同一批 51 张图片的 WebP 档位权衡:
为什么不用 minify-html
本来优先试了 Rust 的
minify-html:快近 10 倍,产物还更小。换成它之后逐字节对比输出,才看出它会丢掉空属性值。MkDocs Material 的可折叠导航直接拿
label[tabindex]当选择器,而模板渲染出来的正是tabindex=""。空属性一被吞掉,导航的
aria-expanded就再也不会更新。上游没有保留空属性的配置项,所以还是留着 htmlmin2,用上面那层外置缓存把性能差距瞬间抹平。