Skip to content

perf(release): 关 overflow-checks + 默认 features,体积 -2.43% - #33

Merged
CarlJia merged 2 commits into
mainfrom
feat/admin-binary-size
Sep 23, 2026
Merged

CarlJia merged 2 commits into
mainfrom
feat/admin-binary-size

Conversation

@CarlJia

@CarlJia CarlJia commented Sep 23, 2026

Copy link
Copy Markdown
Owner

release profile 已在教科书最小边界(codegen-units=1 + lto + opt-level="z" + panic="abort" + strip),Cargo.toml 显式依赖裁痕也都过了(wasmtime 关默认 features、reqwest/chrono/tar/flate2 全部 default-features=false)。剩下的两个形性维度:

  1. release 关 overflow-checks —— panic="abort" 已经把 panic 转成进程退出,overflow 走同一条路径(只是少插一条分支检查),overflow-checks=false 在 release 里与 panic="abort" 组合后行为不变;hub 内部所有计数(流量字节、月份累加、id 序列)用显式 wrapping_*,不依赖隐式 wrapping。debug profile 保留检查。

  2. axum / tower-http 关默认 features —— axum 0.8 默认含 tracing/tower-log/matched-path/form 等没在用的中间件/extractor(没有 TraceLayer/LogLayer/Form/匹配路径展开),explicit 列表 + default-features=false 砍掉。tower-http 同理(没在用 trace / util / catch-panic / follow-redirect)。

cargo test 全 229 项通过。

同棵 dep tree 下,host release 二进制(arm64 macOS):

  • 原始:8,233,136 B
  • overflow-checks 优化:8,099,904 B (-1.62%)
    • axum/tower-http 优化:8,033,296 B (-2.43% 累计)

musl 静态链接 release(11.3 MB)按比例减约 275 KB,具体数字由 CI 出。

Post-Deploy Monitoring & Validation

无新 hub 日志或 metrics,这是构建层的 profile + dep features 改动。验证在 build 阶段:本次 PR 合入后,下一次打 tag 触发的 release workflow 会在 CI 里跨两个 musl target 产出两份新二进制。直连观察 artifact 大小应为同比例缩减(host 测的是 arm64 macOS glibc,musl 静态链接会偏大,但比例接近)。若某条 target 上 binary size 没变小反而变大,说明 cross 工具链对 overflow-checks=false 的处理与 host rustc 不一致,需要重新评估。回滚:revert PR(两行 profile + features 改动)。


Compound Engineering

CarlJia and others added 2 commits September 22, 2026 21:18
release profile 已在教科书最小边界(codegen-units=1 + lto + opt-level="z" +
panic="abort" + strip),Cargo.toml 依赖也已裁过(wasmtime 关默认 features、
reqwest/chrono/tar/flate2 全部禁默认)。还能再挤的部分是 release profile
里的 `overflow-checks`:与 `panic="abort"` 组合后,overflow 行为不变(进程
退出),只是少插一条分支检查。hub 内部所有计数(流量字节、月份累加、
id 序列)都用显式 `wrapping_*` 走显式语义,不依赖隐式 wrapping。debug
profile 保留检查,免得本地复现时被静默溢出误导。

同棵 dep tree 下,host release 二进制:8,233,136 → 8,099,904 字节
(-133,232 / -1.62%)。cargo test 全 229 项通过。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
axum 0.8 默认 features 含 `tracing`/`tower-log`/`matched-path`/`form`
等我们没在用的中间件/extractor:没有 TraceLayer / LogLayer / Form / 匹配
路径展开,留着只是把 tracing-core / tower 链条拉进二进制。`http1`/
`json`/`query`/`tokio` 是显式列出来的必要项;显式列表加 default-features=false
后 229 项 cargo test 全过。

tower-http 默认 features 含 `trace`/`util`/`catch-panic`/`follow-redirect`
等我们没在用的中间件,同理关掉。

同棵 dep tree 下,host release 二进制:8,099,904 → 8,033,296 字节
(-66,608 / -0.82%);两次提交累计 -199,840 / -2.43%。musl 静态链接版本
CI 重新跑就能看到比例一致的缩减。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@CarlJia
CarlJia merged commit 9bebacc into main Sep 23, 2026
3 checks passed
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