Skip to content

perf(size): precompute compressed ops manifest, drop runtime schemars, and tighten packaging - #537

Merged
eric8810 merged 2 commits into
arcships:masterfrom
cunninghamcard-bit:perf/precompute-manifest-drop-schemars
Nov 25, 2026
Merged

eric8810 merged 2 commits into
arcships:masterfrom
cunninghamcard-bit:perf/precompute-manifest-drop-schemars

Conversation

@cunninghamcard-bit

@cunninghamcard-bit cunninghamcard-bit commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Zero-functionality-loss binary and package size reduction (all 55 providers, all modalities, jsonschema validation, realtime/ws, all 14 C ABI exports, and byte-for-byte identical manifest JSON & digest 2c06887e117851bc776b2ecf801caa23e82324d4b906b7764d7f6319a1577284 preserved; root [profile.release] stays opt-level = "z"):

  1. Precomputed compressed ops manifest + drop runtime schemars (aimux-ops, aimux-codegen, aimux-ffi, bindings/node, bindings/python)
    • Moved live schemars manifest generation (generate_manifest()) and TypeRef::schema behind the opt-in aimux-ops/runtime-manifest feature (enabled by aimux-codegen and type_schemas tests).
    • Default builds embed a deterministic pure-Rust miniz_oxide zlib-9 snapshot (aimux-ops/src/manifest.json.zlib, 58,988 B vs 321,763 B raw JSON) and digest (aimux-ops/src/manifest.digest, 64 hex chars), allowing LTO + dead-code elimination to strip schemars's JsonSchema machinery from shipped native libraries.
    • Added aimux_ops::manifest::manifest_json() and routed aimux_manifest_json / Node / Python bindings directly to the cached canonical JSON string without an extra parse/re-serialize pass.
    • aimux-codegen generates and --check drift-checks both aimux-ops/src/manifest.json.zlib and aimux-ops/src/manifest.digest against the live schemars generator (generate_manifest()).
  2. Minify embedded provider tables at build time (aimux-providers)
    • Added a zero-dependency aimux-providers/build.rs that strips JSON whitespace outside strings into $OUT_DIR/provider_registry.min.json (57,044 → 43,369 B, −13,675 B) and $OUT_DIR/provider_aliases.min.json (2,215 → 1,969 B, −246 B) while keeping the source JSON files readable and compatible with sync_registry.py.
  3. Tighten tokio features (Cargo.toml, bindings/node/Cargo.toml, bindings/python/Cargo.toml)
    • Replaced features = ["full"] with the explicit subset used in the workspace (rt, rt-multi-thread, sync, time, macros, net, io-util, process).
  4. Deflate-9 archive packaging (.github/workflows/release.yml, scripts/stage_release_assets.py)
    • Enabled --compression-method deflated --compression-level 9 on Python wheel release publishing via maturin.
    • Switched stage_release_assets.py directory zipping (aimux_ffi.xcframework.zip) from default Deflate-6 (shutil.make_archive) to explicit Deflate-9 (zipfile.ZipFile(..., compresslevel=9)).
  5. Docs, CI & Changelog
    • Updated docs/rfc-0039-implementation.md to document the build-time precomputed manifest snapshot and opt-in runtime-manifest feature.
    • Added standalone aimux-ops feature-off clippy and test steps (--no-default-features) in .github/workflows/ci.yml so the snapshot-only path is covered independently of workspace feature unification.
    • Documented the removal of aimux_ops::op::TypeRef::schema from default builds under CHANGELOG.md (Unreleased / Breaking).

Measured Size Delta (aarch64-apple-darwin, release, opt-level = "z")

  • Reviewer-verified libaimux_ffi.dylib delta: −368,432 B (−4.16%) (16 KiB arm64 page-alignment difference vs local MacOSX26.5 SDK build below).
Artifact / Section Baseline (585fb9990, local SDK) Branch (opt-level = "z") Delta
libaimux_ffi.dylib (raw, reviewer-verified) — — −368,432 B (−4.16%)
libaimux_ffi.dylib (gzip -9, local SDK) 4,545,563 B 4,411,454 B −134,109 B (−2.95%)
__TEXT.__text (local SDK) 6,602,620 B 6,285,436 B −317,184 B (−4.80%)
__TEXT.__const (local SDK) 1,248,576 B 1,218,464 B −30,112 B (−2.41%)
__DATA_CONST.__const (local SDK) 578,176 B 566,288 B −11,888 B (−2.06%)
__LINKEDIT (local SDK) 196,608 B 180,224 B −16,384 B (−8.33%)

Verification

  • cargo fmt --all -- --check
  • cargo clippy -p aimux-ops -p aimux-ffi --no-default-features --all-targets -- -D warnings (snapshot-only default path)
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo run -p aimux-codegen -- --check
  • cargo test -p aimux-ops --no-default-features (standalone snapshot-only path) & cargo test -p aimux-ops --features runtime-manifest (live schemars + byte-for-byte snapshot equality + type_schemas)
  • cargo test -p aimux-ffi, cargo test -p aimux-codegen, cargo test -p aimux-providers --lib preset::tests, cargo test -p aimux-providers --lib catalogue::tests, cargo test -p aimux-core --lib
  • cargo check --manifest-path bindings/node/Cargo.toml & cargo check --manifest-path bindings/python/Cargo.toml
  • Live ctypes smoke test against release libaimux_ffi.dylib: verified all 14 C exports, aimux_abi_version() == 65536, aimux_manifest_json() exact 321,763 B / 72 ops / 328 packages / digest 2c06887e117851bc776b2ecf801caa23e82324d4b906b7764d7f6319a1577284, runtime.describe, and preset provider.create("abacus")
  • bash scripts/check_provider_boundaries.sh, python3 scripts/check_layout.py, python3 -m unittest discover -s scripts/tests -p 'test_*.py' (63/63), python3 scripts/sync_registry.py --check --source models-dev --snapshot registry/models_dev_snapshot.json
  • cargo package --list -p aimux-ops --allow-dirty & -p aimux-providers --allow-dirty verified snapshot files and build.rs are included

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实现验证很好:321,763B manifest/digest 与 base 完全一致,14 个 C export 可解析,快照/压缩体积和 tokio feature 集都对。请补:1) docs/rfc-0039-implementation.md 仍称 runtime manifest/schemars schema,需更新; 2) CI 增加 aimux-ops 默认(feature-off)测试,确保 snapshot-only 路径被覆盖; 3) CHANGELOG 标明 TypeRef::schema 公共字段移除。另实际 dylib 降幅是 -368,432B/-4.16%,请修正文案。

@cunninghamcard-bit
cunninghamcard-bit force-pushed the perf/precompute-manifest-drop-schemars branch from e7e9404 to 71bc3f0 Compare November 23, 2026 13:02
@cunninghamcard-bit

Copy link
Copy Markdown
Contributor Author

@eric8810 感谢细致复测!4 项已全部在最新 commit 71bc3f05(并已 rebase 到最新 master b6ae32c08)补齐:

  1. docs/rfc-0039-implementation.md:已同步更新总览、依赖图、Manifest 生成链与 Verification gates 表格,明确区分构建期 runtime-manifest (schemars) 与默认构建的预计算压缩快照(manifest.json.zlib + manifest.digest)。
  2. .github/workflows/ci.yml:在 rust-test 新增 cargo clippy -p aimux-ops -p aimux-ffi --no-default-features --all-targets -- -D warnings 与 cargo test -p aimux-ops --no-default-features,独立于 workspace feature 合并覆盖 snapshot-only 路径。
  3. CHANGELOG.md:在 ## [Unreleased] → ### Breaking 明确标明默认构建移除 aimux_ops::op::TypeRef::schema 公共字段并迁入 aimux-ops/runtime-manifest feature。
  4. PR 正文体积文案:已按实测复核修正为 −368,432 B (−4.16%)。

本地已重跑 cargo fmt --all -- --check、cargo clippy -p aimux-ops -p aimux-ffi --no-default-features --all-targets -- -D warnings、cargo test -p aimux-ops --no-default-features、cargo run -p aimux-codegen -- --check 与 YAML 语法检查全绿,麻烦再 review 一下!

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

71bc3f0 已补齐三点:RFC-0039 实现文档改为描述 snapshot + runtime-manifest feature;CI 增加 aimux-ops/aimux-ffi --no-default-features clippy 和 aimux-ops 默认 feature-off 测试;CHANGELOG 明确 TypeRef::schema 在默认构建移除。体积文案已修正为 -368,432B/-4.16%。20 项 CI 绿。Approve。但当前与 master 冲突(#538 已合入,改了 op.rs/op.rs 相关文件),rebase 后我再合。

@eric8810

Copy link
Copy Markdown
Contributor

已 approve,但合并前需要 rebase 到 master(#538 改了 op.rs/op.rs 周边,当前 CONFLICTING)。rebase 后 CI 绿我会直接合。

@eric8810

Copy link
Copy Markdown
Contributor

再提醒一下:这个 PR 已 approve,但还需要 rebase 到当前 master(707c591b),目前仍是 CONFLICTING。rebase 后 CI 绿我直接合。

@cunninghamcard-bit

Copy link
Copy Markdown
Contributor Author

@eric8810 已 rebase 到最新 origin/master (707c591b8) 并解完冲突,最新 HEAD e252f3b49 已推送。

本地验证全绿:

  • cargo fmt --all -- --check
  • cargo clippy -p aimux-ops -p aimux-ffi --no-default-features --all-targets -- -D warnings
  • cargo clippy -p aimux-ops -p aimux-ffi -p aimux-codegen --all-targets -- -D warnings
  • cargo test -p aimux-ops --no-default-features & cargo test -p aimux-ops -p aimux-ffi -p aimux-codegen
  • cargo run -p aimux-codegen -- --check
  • bindings/node & bindings/python cargo check

待 CI 绿后麻烦直接合入!

@eric8810

Copy link
Copy Markdown
Contributor

注意 rebase 后 CI 会撞到 master 上一个已存在的红:aimux-ffi (aarch64-apple-darwin) 的 test_macho_dylib_exports_end_to_end 断言导出数是 14,但 #538 加了两个 async 导出后实际是 16。这个正在 #542 里修;rebase 后如果只红这一项不用处理,#542 合入后我重跑即可。

@eric8810

Copy link
Copy Markdown
Contributor

rebase 提醒 + 一个依赖:你当前 head 的 CI 只红 aimux-ffi (aarch64-apple-darwin) 的 assertEqual(len(exports), 14)(实际 16,#538 引入的 master 遗留)。这个断言修复在 #542(已 approve,等作者 rebase 后合入)。所以顺序是:#542 合入 → 你 rebase 到新 master → CI 全绿 → 我合。如果 #542 迟迟不动,你也可以在自己分支上把 scripts/tests/test_check_native_artifact.py:522 的 14 改成 16 顶一下。

@eric8810

Copy link
Copy Markdown
Contributor

#542 已合入 master(8a5df14e),导出断言已是 16,UAF race 也修了。现在只差你 rebase 到 master;rebase 后 CI 应该全绿,我直接合。

@eric8810
eric8810 dismissed their stale review November 24, 2026 10:25

All points in this review were addressed in later commits; current head re-reviewed and approved by eric8810. Dismissing my own stale review so only CI gates the merge.

@eric8810

Copy link
Copy Markdown
Contributor

master 现在是 178885a,CI 全绿。这个 PR 是最后一个等 rebase 的已 approve 项,麻烦 sync/rebase 一下,绿了我立刻合。

@eric8810

Copy link
Copy Markdown
Contributor

master 现在是 0.7.0(#546 已合并,v0.7.0 已发布)。你的分支落后 57 个 commit,直接冲突的文件:Cargo.toml、bindings/node/Cargo.toml、bindings/python/Cargo.toml、CHANGELOG.md、docs/rfc-0039-implementation.md、tools/aimux-codegen/generated-files.json。

rebase 时请注意:

  • 三个 Cargo.toml 保留 version = "0.7.0"(workspace 用 version.workspace = true 的地方不用动)
  • CHANGELOG.md:把你的条目从 [Unreleased] 之外(如果 rebase 后落到了 [0.7.0] 段里)挪回顶部新的 ## [Unreleased] 下,不要改动 [0.7.0] 段
  • docs/rfc-0039-implementation.md 和 generated-files.json 按 master 的现状重新应用你的改动

rebase 后 CI 绿我就合(进 0.7.1)。代码本身我已 approve。

@cunninghamcard-bit
cunninghamcard-bit force-pushed the perf/precompute-manifest-drop-schemars branch from e252f3b to 39637dc Compare November 25, 2026 02:58
@cunninghamcard-bit

Copy link
Copy Markdown
Contributor Author

@eric8810 已按要求 rebase 到最新 v0.7.0 origin/master (a3b29f182) 并刷新预计算 manifest 快照,最新 HEAD 39637dcef 已推送:

  • 三个 Cargo.toml(根、bindings/node、bindings/python)保持 version = "0.7.0"
  • CHANGELOG.md 中 perf(size): precompute compressed ops manifest, drop runtime schemars, and tighten packaging #537 条目已归位顶部新的 ## [Unreleased] 下,未改动 [0.7.0] 段
  • docs/rfc-0039-implementation.md(更新至 master 当前 76 ops / 321 referenced types)与 tools/aimux-codegen/generated-files.json 已基于 master 现状重应用,并重跑 aimux-codegen 刷新 v0.7.0 压缩 manifest 快照(manifest.digest 与 --check 一致)

本地验证全绿:cargo fmt --all -- --check、默认与含 codegen 的 cargo clippy -D warnings、aimux-ops --no-default-features 与 aimux-ops/ffi/codegen 单测、aimux-codegen --check、bindings/{node,python} cargo check、以及 python3 -m unittest discover -s scripts/tests(67/67 OK)。待 CI 绿后麻烦直接合入!

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase 到 0.7.0 master 后复核:diff 不动 version 行,CHANGELOG 条目落在新的 [Unreleased] 段,[0.7.0] 段未改;tokio feature 收窄和 miniz_oxide 快照路径与之前 approve 的版本一致。20/20 CI 绿。Approve,合入后进 0.7.1。

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.

2 participants