Repository navigation
perf(build): compile libsqlite3-sys at O3 and drop no-op dist wrapper overrides - #7209
Merged
Merged
Conversation
… overrides Compile bundled SQLite + FTS5 (libsqlite3-sys) at opt-level = 3 in [profile.dist] and remove the no-op flate2 and zstd thin-wrapper overrides whose O3 setting did not propagate into zlib-rs/miniz_oxide or zstd-sys. libsqlite3-sys is compiled by cc as a C static library so it adds no Rust IR to ThinLTO peak RSS on 7 GB CI runners, grows maka by only +0.69 MB (+0.32 MB gzip), and reduces SQLite read/tail latency. Generated-by: Maka (Gemini)
me2seeks
approved these changes
Nov 23, 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.
Summary
English
What changed
Refines
[profile.dist]per-packageopt-level = 3overrides inCargo.tomlbased on empirical profiling and real-Host stress benchmarks:[profile.dist.package.libsqlite3-sys] opt-level = 3: Compiles bundled SQLite + FTS5 (sqlite3.c) at-O3instead of-Os. Becauselibsqlite3-sysis a pure C static library compiled bycc, it adds zero Rust IR to ThinLTO (flatrustcpeak RSS on 7 GB CI runners) while delivering measurable SQLite read/tail-latency gains for +0.69 MB (+0.32 MBgzip) binary delta.flate2andzstd: Both are thin Rust wrapper crates whoseopt-level = 3does not propagate into their underlying compression backends (zlib-rs/miniz_oxideand Czstd-sys, which remained at-Os). Empirically bumpingzstd-sys+zlib-rsto-O3only movedapplication composeby-0.6%, so removing these two wrapper shells cleans up dead config with zero regression.Refs #7185, #7189, #7193, #7194, #7204.
Empirical Experimental Results
All local builds and runtime benchmarks were conducted on macOS ARM64 (
rustc 1.100.0, pinned prebuiltlibrusty_v8.a,panic = "unwind").1. Isolated A/B Verification of This Exact PR (
baselinevscandidate: +libsqlite3-sys=3, -flate2, -zstd)dist)makabinary size__TEXT,__textcode sectionmakagzip -6 sizemaka-python-workersizemakarustcpeak RSS (default parallelism)makarustcuser CPUultra_long_sessionwall (3 pairs, 6/6 pass)ultra_long_sessionWS 15-turn sum[4924, 4911, 4894])[4872, 4864, 4838])historyp99 (~378 reads/run)[11, 11, 11])[9, 9, 10])(Confirmed
libsqlite3-sys 0.39.0build script receivesOPT_LEVEL=3forsqlite3/sqlite3.c. Cold--version4v4 samples overlapped within SSD/AMFI variance: baseline[2084, 1532, 1551, 1541]ms vs candidate[1669, 1764, 1829, 1574]ms; warm--version15v15:9.01vs9.38ms.)2. Why Not Blanket
opt-level = 3? (Head-to-Headdist_svs Fulldist_o3Stress Test)Same clean
main(19e5caf51), counterbalancedS / O3 / O3 / Sruns on 4 real-Host stress suites plusmincore=0cold startup:dist_s(currentdist)dist_o3(all cratesO3)O3vss)makabinary /__TEXT,__textmakagzip -6rustcpeak RSS (default parallelism) / user CPU--version(mincore=0, 4v4 non-overlapping)Takeaway: Setting all 500+ remaining crates to
O3has a 2%–5.7% warm ceiling under extreme load, while causing +73 MB binary bloat, +29.1% slower cold startup, +10–17 MiB runtime RSS, and +25.6% higherrustcpeak RSS (pushing 7 GBmacos-latestCI runners past OOM, sincedist_satCARGO_BUILD_JOBS=3already peaks at6.95 GiBprocess-group RSS).3. Tier 4 Architecture Matrix (928 Interleaved Samples on
main 1a940845b,CARGO_BUILD_JOBS=3)maka/ npm.tgz/.dmgs, ThinLTO, 16 CGU)+libsqlite3-sys/zstd-sys/zlib-rs=3,-zstd/-flate2)-17.8%..-14.0%);compose: -0.6%build-ui-15.9%, cold start +0.2%, Recall -1.4%s,lto="fat", 1 CGU)build-ui-12.1%, Python worker -13.4%3-platform linker audit: macOS
-dead_strip_dylibssaved only 80 B with zero statistical latency change and-no_deduplicatesaved 0 B; Linuxzig 0.17.1rejects--icf=safe; Windows MSVC already passes/OPT:REF,ICFby default. None of those extra linker flags are worth adding.Projected Optimal Configuration on High-Memory Build Runners (32 GB+ Release Runner)
If release builds (e.g., tagged stable releases, without increasing daily Nightly runner spend) move to a 32 GB+ RAM build runner, the optimal configuration is
FatLTO (lto = "fat", codegen-units = 1)+opt-level = "s"+ the refined overrides (includinglibsqlite3-sys = 3):dist+ this PR)FatLTO+ this PR)makamacOS binarymaka-desktop-shellmacOS binary.tgz.dmginstaller--version,mincore=0)libsqlite3-sys = 3)6.95 GiBprocess group)Note: Even on 32 GB+ runners, PGO is still not recommended for standard releases (doubles CI duration to ~38 min, adds fragile training pipelines, inflates package size by +2.75%, and gives no cold-start/Recall improvement over FatLTO +
libsqlite3-sys = 3).简体中文
改动内容
基于实测 profiling 和多套真实 Host 压力测试,收敛
Cargo.toml中[profile.dist]的单包opt-level = 3覆写列表:[profile.dist.package.libsqlite3-sys] opt-level = 3:让内置的 SQLite + FTS5(sqlite3.c)从-Os改为-O3编译。由于libsqlite3-sys是cc编译的纯 C 静态库,不会向rustcThinLTO 注入任何 Rust IR(对 7 GB CI runner 的编译峰值内存零压力),仅增加 +0.69 MB(gzip +0.32 MB)体积,即可换取明确的 SQLite 读路径与长尾延迟收益。flate2和zstd:这两个 crate 只是 Rust 薄壳包装,其opt-level = 3并不会传递到底层压缩实现(zlib-rs/miniz_oxide和 C 后端zstd-sys基线仍按-Os编译);且实测把zstd-sys+zlib-rs真拉到-O3对application compose也仅差-0.6%。删除这两个无效壳子可减少死配置且无性能回退。关联 PR:#7185、#7189、#7193、#7194、#7204。
实验结果汇总
所有本地构建与压测均在 macOS ARM64(
rustc 1.100.0,锁定预编译librusty_v8.a,panic = "unwind")完成。1. 本 PR 精确隔离 A/B 验证(
baselinevscandidate:+libsqlite3-sys=3, -flate2, -zstd)dist)maka二进制体积__TEXT,__text代码段makagzip -6 体积maka-python-worker体积makarustc峰值 RSS(默认并发)makarustcuser CPUultra_long_session耗时(3 组交错,6/6 全过)ultra_long_sessionWS 15 轮总耗时[4924, 4911, 4894])[4872, 4864, 4838])historyp99(每轮 ~378 次读)[11, 11, 11])[9, 9, 10])(已确认
libsqlite3-sys 0.39.0构建脚本以OPT_LEVEL=3编译sqlite3/sqlite3.c。冷启--version4v4 样本分布重叠在磁盘/AMFI 波动内:baseline[2084, 1532, 1551, 1541]ms vs candidate[1669, 1764, 1829, 1574]ms;热启 15v15:9.01vs9.38ms。)2. 为什么不全部
opt-level = 3?(dist_svs 全量dist_o34 套真实 Host 压测对决)同一干净
main(19e5caf51),对称交错S / O3 / O3 / S实测 4 套真实 Host 压测 +mincore=0冷启:dist_s(当前dist)dist_o3(全量O3)O3vss)maka文件体积 /__TEXT,__textmakagzip -6rustc峰值 RSS(默认并发)/ user CPU--version(mincore=0,4v4 区间不重叠)结论:把剩下 500 多个 crate 全拉到
O3,极限压测下的热态收益上限只有 2%–5.7%,却要付出 +73 MB 体积、冷启慢 29.1%(+477 ms)、常驻内存多吃 10–17 MiB、编译器峰值内存涨 +25.6%(dist_s在CARGO_BUILD_JOBS=3下进程组峰值已达6.95 GiB,全量O3会直接顶爆 7 GBmacos-latestCI runner)。因此只需精准保留热点内核(补上libsqlite3-sys),不再扩充 RustO3名单。3. Tier 4 全方案对比矩阵(
main 1a940845b,928 条交错实测样本,CARGO_BUILD_JOBS=3)maka/ npm.tgz/.dmgs、ThinLTO、16 CGU)+libsqlite3-sys/zstd-sys/zlib-rs=3、-zstd/-flate2)-17.8%..-14.0%);compose-0.6%build-ui-15.9%,冷启 +0.2%,Recall -1.4%s、lto="fat"、1 CGU)build-ui-12.1%、Python worker -13.4%三平台 linker 审计结论:macOS
-dead_strip_dylibs仅省 80 B 且延迟置信区间跨零、-no_deduplicate省 0 B;Linuxzig 0.17.1直接拒--icf=safe;Windows MSVC 默认已启用/OPT:REF,ICF。因此三平台均不额外增加 linker 参数。编译机器资源充足时的最优预估方案(32 GB+ 正式发版 Runner)
如果未来针对**正式版本发版(tag release,不给每日 Nightly 增加大规格机器成本)**提供 32 GB+ 内存编译机,综合体积与性能的最优配置是
FatLTO (lto = "fat", codegen-units = 1)+opt-level = "s"+ 精简后的热点覆写(含本 PR 的libsqlite3-sys = 3):dist+ 本 PR)FatLTO+ 本 PR)makamacOS 二进制maka-desktop-shellmacOS 二进制.tgz.dmg安装包--version,mincore=0)libsqlite3-sys = 3)6.95 GiB)注:即便在 32 GB+ 编译机上,仍不建议默认引入 PGO(全流程翻倍到 ~38 分钟、引入易碎的训练语料维护成本、包体反而涨 +2.75%,且在冷启和 Recall 上不如
FatLTO + libsqlite3-sys = 3)。Verification
cargo build --locked --profile dist -p libsqlite3-sys -vvpassesOPT_LEVEL=3when compilingsqlite3/sqlite3.c.baselinevscandidate:+libsqlite3-sys=3, -flate2, -zstd) covering binary/section/gzip sizes, finalrustcpeak RSS,mincore=0cold startup,host_load_stress::real_host_ultra_long_session_and_compaction_stress(3 pairs, 6/6 passed), andhost_hell_stress::real_host_200_turn_mega_session_huge_payloads_5level_fork_and_queue_grinder(3 pairs, 6/6 passed).git diff --checkandcargo fmt --checkpassed.distNightly builds (covered by CI and subsequent Nightly run).AI use
Select exactly one:
Tool(s) and scope: Maka (Gemini) and Magpie (
codex/gpt-6.2-astra) ran the empirical[profile.dist]benchmarks, stress tests, dependency audit,Cargo.tomledit, and PR write-up.Generated-by: Maka (Gemini)
Checklist
-vvflag inspection and real-Host stress A/B benchmarks)Does this PR entail a breaking change or persisted-data migration?
upgrade_compat.rscoverage under Summary aboveDoes this PR entail a change in behavior?