diff --git a/Cargo.toml b/Cargo.toml index 5f1f2eabb5a..a2144534064 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -307,17 +307,36 @@ opt-level = 3 [profile.dev.package.sonora-simd] opt-level = 3 +# The Go mirror stores native staticlibs in Git, whose per-file limit is 100 MB. +# Keep all release entry points on the same compact native profile. [profile.release] panic = "abort" +lto = "fat" +codegen-units = 1 +strip = "symbols" + +# UniFFI reads ELF's regular symbol table to generate bindings, including in +# maturin and downstream generators. Remove debug data but retain that metadata. +[profile.release.package.moq-ffi] +strip = "debuginfo" [profile.profiling] inherits = "release" debug = "line-tables-only" +strip = "none" # frame pointers: pass RUSTFLAGS="-C force-frame-pointers=yes" when building +# Package overrides are inherited too and take precedence over the profile. +[profile.profiling.package.moq-ffi] +strip = "none" + [profile.release-with-debug] inherits = "release" debug = true +strip = "none" + +[profile.release-with-debug.package.moq-ffi] +strip = "none" # Size-optimized build for the browser/WASM bindings (rs/moq-wasm). Shipping over # the wire, so optimize for size, not speed (~579KB -> ~471KB gzipped vs the @@ -325,6 +344,3 @@ debug = true [profile.wasm-release] inherits = "release" opt-level = "z" -lto = "fat" -codegen-units = 1 -strip = true diff --git a/cpp/moq/CMakeLists.txt b/cpp/moq/CMakeLists.txt index 529fbf372b1..fe85ed35ec1 100644 --- a/cpp/moq/CMakeLists.txt +++ b/cpp/moq/CMakeLists.txt @@ -27,12 +27,20 @@ else() endif() if(WIN32) set(MOQ_FFI_LIB "${_cargo_target}/${_profile}/moq_ffi.lib") + set(_metadata "${_cargo_target}/${_profile}/moq_ffi.dll") +elseif(APPLE) + set(MOQ_FFI_LIB "${_cargo_target}/${_profile}/libmoq_ffi.a") + set(_metadata "${_cargo_target}/${_profile}/libmoq_ffi.dylib") else() set(MOQ_FFI_LIB "${_cargo_target}/${_profile}/libmoq_ffi.a") + set(_metadata "${_cargo_target}/${_profile}/libmoq_ffi.so") endif() find_program(UNIFFI_BINDGEN_CPP uniffi-bindgen-cpp REQUIRED) +# Read metadata from the linked cdylib, like the other binding generators, +# without depending on UniFFI support for every static archive object format. +# Linking still uses the staticlib, so consumers need no runtime shared library. # Rendered to a scratch directory and copied only when changed, so a no-op cargo build does # not recompile the bindings. set(_generated "${CMAKE_CURRENT_BINARY_DIR}/include/moq/ffi") @@ -43,12 +51,12 @@ list(TRANSFORM _generated_files PREPEND "${_render}/" OUTPUT_VARIABLE _render_pa add_custom_target(moq_ffi ALL COMMAND cargo build --locked --package moq-ffi ${_cargo_flags} COMMAND ${CMAKE_COMMAND} -E rm -rf "${_render}" - COMMAND "${UNIFFI_BINDGEN_CPP}" --library "${MOQ_FFI_LIB}" + COMMAND "${UNIFFI_BINDGEN_CPP}" --library "${_metadata}" --config "${CMAKE_CURRENT_SOURCE_DIR}/uniffi.toml" --out-dir "${_render}" COMMAND ${CMAKE_COMMAND} -E make_directory "${_generated}" COMMAND ${CMAKE_COMMAND} -E copy_if_different ${_render_paths} "${_generated}" WORKING_DIRECTORY "${_workspace}" - BYPRODUCTS "${MOQ_FFI_LIB}" ${_generated_paths} + BYPRODUCTS "${MOQ_FFI_LIB}" "${_metadata}" ${_generated_paths} COMMENT "Building moq-ffi and rendering its C++ bindings" VERBATIM ) diff --git a/cpp/moq/build.sh b/cpp/moq/build.sh index e9a3c14e342..694e9a44b24 100755 --- a/cpp/moq/build.sh +++ b/cpp/moq/build.sh @@ -10,11 +10,6 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -# Shrink the release staticlib the way rs/moq-c/build.sh does: thin LTO with one codegen -# unit dead-strips the monomorphizations Rust bakes into a staticlib. -export CARGO_PROFILE_RELEASE_LTO="${CARGO_PROFILE_RELEASE_LTO:-thin}" -export CARGO_PROFILE_RELEASE_CODEGEN_UNITS="${CARGO_PROFILE_RELEASE_CODEGEN_UNITS:-1}" - TARGET="" OUTPUT_DIR="dist" diff --git a/nix/overlay.nix b/nix/overlay.nix index 98709591531..19424f7b165 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -135,14 +135,6 @@ let rustPlatform.bindgenHook ]; - # libmoq.a carries moq-ffi's whole dep tree, so an unstripped build is - # ~75 MB+. Thin LTO with a single codegen unit dead-strips the unused - # monomorphizations Rust bakes into a staticlib, halving the artifact - # with no source or ABI change, which keeps the release tarball and - # brew download small. Mirrors rs/moq-c/build.sh's Windows cargo path. - CARGO_PROFILE_RELEASE_LTO = "thin"; - CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "1"; - # moq-c is a staticlib; crane's default install phase only handles # binaries. Lay out the artifact tree the way release tarballs and # downstream `find_package(moq-c)` consumers already expect. diff --git a/quest/m1/README.md b/quest/m1/README.md index 3136b7c6bf7..c975e9a34e5 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -173,7 +173,6 @@ session outcomes, and embedder refusals inside session outcomes. - [moqsrc A/V alignment](/quest/m1/gst-src-av-sync.md) - every `moqsrc` pad of a run shares one timestamp reference and segment base - [TS passthrough export](/quest/m1/ts-passthrough-export.md) - `export ts --passthrough` writes the `m2ts` track back byte-identical (less late drops) on a fixed delay - [FLV and MKV export delay](/quest/m1/export-delay.md) - FLV and MKV interleave through the shared jitter buffer on a fixed delay, breaking the CLI once -- [Release profile](/quest/m1/release-profile.md) - every release build gets fat LTO, one codegen unit, and stripping from the workspace profile instead of three script exports - [Size report](/quest/m1/size-report.md) - a nightly job reports every shipped artifact's size, native and JS, and alerts when one grows - [Bindings size profile](/quest/m1/ffi-size-profile.md) - a benchmark decides whether the moq-ffi builds ship at opt-level "s", which halves the dylib - [Go mirror delivery](/quest/m1/go-mirror-delivery.md) - the Go binding's staticlibs stop growing git history by ~210 MiB per release diff --git a/quest/m1/ffi-size-profile.md b/quest/m1/ffi-size-profile.md index 70a00e73639..c1d981a50ee 100644 --- a/quest/m1/ffi-size-profile.md +++ b/quest/m1/ffi-size-profile.md @@ -24,7 +24,3 @@ Guidance: - If it's adopted, use a named profile (for example `[profile.ffi]`, inheriting release) that every binding build path selects, so the relay and self-builders keep opt-level 3. - -## Required - -- [Release profile](/quest/m1/release-profile.md) - the baseline this compares against diff --git a/quest/m1/go-mirror-delivery.md b/quest/m1/go-mirror-delivery.md index df439a1d7bd..ac0294f3dcb 100644 --- a/quest/m1/go-mirror-delivery.md +++ b/quest/m1/go-mirror-delivery.md @@ -17,11 +17,8 @@ limit, and each release adds about 210 MiB of history. - a module proxy we host - release assets fetched by a build step Git LFS is out, because the Go module proxy doesn't serve LFS objects. -- The release profile quest shrinks the staticlibs (121 to 41 MiB on macOS), - which buys headroom but doesn't stop the history growth. +- The workspace release profile (fat LTO, one codegen unit) shrinks the + staticlibs (121 to 41 MiB on macOS), which buys headroom but doesn't stop + the history growth. - Deliverable: the chosen approach recorded here, and a follow-up quest to implement it. Split this if the prototype turns out large. - -## Related - -- [Release profile](/quest/m1/release-profile.md) - shrinks what the mirror carries diff --git a/quest/m1/perf/lock-profile.md b/quest/m1/perf/lock-profile.md index 572e5fb5574..a74a752f215 100644 --- a/quest/m1/perf/lock-profile.md +++ b/quest/m1/perf/lock-profile.md @@ -86,4 +86,3 @@ CPU and heap: - [kio channel contention](/quest/m1/perf/kio-channel-contention.md) - requires this for its before and after - [Benchmark reporting](/bench/README.md) - shares the workload lifecycle and artifact conventions -- [Release profile](/quest/m1/release-profile.md) - also changes the profile `[profile.profiling]` inherits; land one, then rebase the other diff --git a/quest/m1/release-profile.md b/quest/m1/release-profile.md deleted file mode 100644 index f51a42b6be2..00000000000 --- a/quest/m1/release-profile.md +++ /dev/null @@ -1,52 +0,0 @@ -# [S] Release profile: fat LTO, one codegen unit, stripped - -## Goal - -Every `cargo build --release` produces what we mean to ship: the relay and -CLI binaries, the Python wheel (maturin), Dart's native asset, the nix -packages, and the moq-ffi and moq-c builds all get the same size settings -from `[profile.release]` in the workspace `Cargo.toml`. Today only -`rs/moq-ffi/build.sh`, `rs/moq-c/build.sh`, and `nix/overlay.nix` export -`CARGO_PROFILE_RELEASE_LTO=thin` and one codegen unit, so the PyPI wheel -ships a 31 MiB unstripped `.so` where `build.sh` ships 24 MiB, and the -relay and CLI get no LTO at all. - -Measured on aarch64-apple-darwin, rustc 1.98.1 (2026-09-26): - -| artifact | default release, stripped | fat LTO, 1 CGU, strip | -|---|---|---| -| moq-relay | 26.1 MiB | 22.9 MiB | -| libmoq_ffi.dylib | 21.7 MiB | 20.0 MiB | -| libmoq_ffi.a | 121 MiB (unstripped) | 40.8 MiB | - -Release build time went from 5m to 9m on that machine. - -## Plan - -Decided in planning: - -- `lto = "fat"` and `codegen-units = 1`, not thin: the extra link time is paid - only by release builds, and fat LTO usually helps speed as well as size. -- `strip = "symbols"` everywhere. Released relay binaries already appear - stripped (zig's linker, unconfirmed), and the ffi cdylibs keep their - exported symbols in the dynamic table. Panic backtraces losing function - names is accepted. -- opt-level stays 3 here. A size-optimized profile for the bindings is its own - quest, gated on a benchmark. - -Guidance: - -- Delete the three `CARGO_PROFILE_RELEASE_*` exports. Move the comment about - the Go mirror's 100 MB limit next to the profile. -- `profiling` and `release-with-debug` inherit from release, so they would - inherit the strip too. Override them so they still produce symbolized - captures. `wasm-release` can then drop whatever it now inherits. -- Measure on Linux as well (x86_64 and aarch64), and put sizes and link times - for the release matrix in the PR. Check that the Go mirror's staticlibs - still fit under its limit. - -## Related - -- [Size report](/quest/m1/size-report.md) - the nightly job that shows what this changes over time -- [Bindings size profile](/quest/m1/ffi-size-profile.md) - the opt-level trade this quest leaves out -- [Relay profiling](/quest/m1/perf/lock-profile.md) - the profiling recipe whose captures the `profiling` override keeps symbolized diff --git a/quest/m1/size-report.md b/quest/m1/size-report.md index 71174a84826..8b4e8a709d2 100644 --- a/quest/m1/size-report.md +++ b/quest/m1/size-report.md @@ -41,6 +41,11 @@ Decided in planning: separately. - The work lives in a `sh/` script behind a `just` recipe, and `nightly.yml` calls the recipe. +- Cover Linux x86_64 and aarch64, and record each artifact's release build + time alongside its size. The unified release profile (fat LTO, one codegen + unit, stripped; #5274) landed without a Linux aarch64 artifact matrix or a + controlled before/after build-cost comparison, so this job's first runs + supply them. Check the Go mirror's staticlibs stay under its 100 MB limit. Considered and declined (do not re-ask): @@ -56,5 +61,4 @@ Considered and declined (do not re-ask): ## Related -- [Release profile](/quest/m1/release-profile.md) - the profile this report measures - [Benchmark regressions in CI](/quest/m1/bench-ci.md) - the same nightly-trend shape for Criterion diff --git a/rs/moq-c/build.sh b/rs/moq-c/build.sh index e07690b8fd2..302a2a38670 100755 --- a/rs/moq-c/build.sh +++ b/rs/moq-c/build.sh @@ -16,17 +16,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" RS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" WORKSPACE_DIR="$(cd "$RS_DIR/.." && pwd)" -# Shrink the release staticlib. libmoq.a carries the same heavy dep tree as -# moq-ffi, so an unstripped build is ~75 MB+. moq-c ships as a release -# tarball (not a git mirror, so no hard 100 MB limit like moq-go), but thin -# LTO with a single codegen unit dead-strips the unused monomorphizations Rust -# bakes into a staticlib, halving the artifact with no source or ABI changes. -# This covers the Windows cargo path below; the nix/crane path (Linux/macOS) -# sets the same vars in nix/overlay.nix. Scoped here so a plain -# `cargo build --release` stays fast; a caller can still override. -export CARGO_PROFILE_RELEASE_LTO="${CARGO_PROFILE_RELEASE_LTO:-thin}" -export CARGO_PROFILE_RELEASE_CODEGEN_UNITS="${CARGO_PROFILE_RELEASE_CODEGEN_UNITS:-1}" - TARGET="" VERSION="" OUTPUT_DIR="dist" diff --git a/rs/moq-ffi/build.sh b/rs/moq-ffi/build.sh index 16a6c62e24c..9f50f42d51a 100755 --- a/rs/moq-ffi/build.sh +++ b/rs/moq-ffi/build.sh @@ -14,19 +14,6 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" RS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" WORKSPACE_DIR="$(cd "$RS_DIR/.." && pwd)" -# Shrink the release staticlib. The Go mirror commits the native libs straight -# into git, and GitHub's pre-receive hook hard-rejects any file over 100 MB -# (GH001). An unstripped moq-ffi staticlib is ~110 MB on Linux, which silently -# blocked every moq-go mirror push and pinned consumers to a stale release. -# Thin LTO with a single codegen unit dead-strips the unused monomorphizations -# Rust bakes into a staticlib, cutting it by ~60% (~110 MB to ~35 MB) with no -# source or ABI changes. (Swift ships an XCFramework release asset and Kotlin a -# Maven .so, so neither hits the git limit, but both still get smaller libs.) -# Scoped here via env vars so a plain `cargo build --release` stays fast; a -# caller can still override. -export CARGO_PROFILE_RELEASE_LTO="${CARGO_PROFILE_RELEASE_LTO:-thin}" -export CARGO_PROFILE_RELEASE_CODEGEN_UNITS="${CARGO_PROFILE_RELEASE_CODEGEN_UNITS:-1}" - # Resolve cargo target directory (respects CARGO_TARGET_DIR, .cargo/config, etc.) TARGET_BASE_DIR=$(cargo metadata --format-version 1 --manifest-path "$WORKSPACE_DIR/Cargo.toml" --no-deps 2>/dev/null | sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p' || diff --git a/sh/go/stage.sh b/sh/go/stage.sh index 86db6e827ca..85422dd65e1 100755 --- a/sh/go/stage.sh +++ b/sh/go/stage.sh @@ -139,9 +139,8 @@ echo "go stage: assembling ffi module..." >&2 # --skip-size-check because the lib above is a plain host build, unrelated to # what the mirror publishes. It is a debug build by default now, so it carries # full line-table debug info and measured 619 MiB against a 100 MiB limit; even -# at MOQ_FFI_PROFILE=release it skips the thin LTO that rs/moq-ffi/build.sh -# applies on the publish path. Enforcing the limit here fails on a lib nobody -# publishes. +# at MOQ_FFI_PROFILE=release this staging path is for local checks, not +# publication. The release packager enforces the limit on shipped artifacts. bash "$SCRIPT_DIR/package-ffi.sh" \ --version "0.0.0-dev" \ --source-dir "$GO_DIR/ffi" \