October 19, 2026
2 pull requests merged across 1 repo
Offline-Protocol/offline-protocol-sdk
Merge after #579. This branch does not contain it, and the mobile profile inherits its link-time optimisation from release, which only reaches the library once #579 drops the lib crate type.
What was wrong
ADR 0018, ADR 0019, threat model R11, the C guide's K4, the telemetry sink contract, CLAUDE.md and six code comments said the mobile library shipped under minisize, with panic = "abort". No build ever used minisize: every iOS, Android, desktop and wheel build ran --release. The mobile libraries shipped at opt-level 3 and unwound.
The change
- A
mobileprofile:releaseat opt-level "s", unwinding. The release workflow's Android job, both React Native build scripts (the release's iOS job runs the iOS one) and CI's iOS simulator build use--profile mobile, and read their output fromtarget/<triple>/mobile/. - The desktop libraries and the wheels stay on
release.minisizeis deleted. - Every document and comment that claimed abort now says what ships. ADR 0029 records the decision with both tables below.
- Two guards hold the profile and the four build sites, and keep the desktop builds on
--release.
Why unwinding
Every panic seam in the SDK is a catch_unwind: event handler isolation, the telemetry sink dispatch, the document import, and UniFFI's own conversion of a panic into a Swift or Kotlin exception. panic = "abort" would turn each into a SIGABRT attributed to the app, for a further 19% off the shared library.
Why "s" and not "z"
The plan proposed "z". The benches overruled it. Criterion, macOS arm64, change against opt-level 3:
| Bench | opt-level 3 | "s" | "z" |
|---|---|---|---|
mls_seal_dm | 88.6 µs | +43% | +145% |
mls_open_dm | 101.7 µs | +37% | +115% |
send_message | 4.11 µs | -1% | +46% |
process_loop | 1.43 µs | +8% | +58% |
message_serialization/1000 | 0.70 µs | +30% | +96% |
ble_fragmentation/1000 | 0.99 µs | +33% | +115% |
ble_reassembly/1000 | 3.26 µs | +1% | +83% |
Keeping 30 crypto and codec crates at opt-level 3 under "z" recovered only a third of the MLS cost, and the engine and serialization paths not at all. The data layer has no bench, so its cost at "z" would ship unmeasured. The static library that iOS and npm carry is no larger at "s" than at "z". Moving to "z" later is one word in Cargo.toml and one in the guard.
Size
Every row with #579's link-time optimisation except the first.
| Build | Android arm64 .so | macOS arm64 .dylib |
|---|---|---|
0.29.0 shape (--release, no LTO) | 11,843,344 | 11,534,416 |
| #579 alone | 11,032,352 | 10,932,208 |
#579 + this (mobile, "s") | 8,540,440 | 8,538,400 |
| "z", for comparison | 6,347,712 |
Verified locally
- fmt,
cargo clippy --workspace -- -D warnings,cargo test --workspace --lib, rustdoc under-D warnings. - Both guards, negative-controlled eight ways:
panic = "abort"added,minisizeback, each of the four mobile sites back on--release, a desktop job onmobile, the profile at "z". - The iOS simulator archive built as CI builds it, at the new path, passes the minimum-OS gate.
- Android arm64 built as the script builds it (NDK 27.1, no C binding) passes the 16 KB alignment gate.
Not verified
- The full release workflow at the new paths: worth a
workflow_dispatchdry run with an-rc.Nversion after both PRs merge. This is the first release run through the Android and iOS collection steps since they moved. - Speed on a phone. The benches ran on an M-series Mac.
What was wrong
The release profile sets lto = true, but cargo runs link-time optimisation on a library only when every crate type in its list can take it. The FFI crate listed ["cdylib", "staticlib", "lib"], and an rlib cannot, so cargo passed no LTO flag at all. Every native library from the UniFFI migration (2025-11-07) to 0.29.0 was built without it, on every platform, and no build said so.
The rule is in cargo's source (CrateType::can_lto and the comment in compiler/lto.rs: "a cdylib/rlib combination won't allow LTO") and is cargo issue rust-lang/cargo#2301, closed in 2017 with a workaround and no warning.
The change
- The crate's types are now
cdylibandstaticlib. The release build now passes-C lto. tools/capi-fuzzwas the only thing linking the crate as Rust. It now compiles the crate's ownlib.rsunder its own package, with its own build script generating the scaffolding from the same interface definition. The fuzz target is unchanged.- Two guards:
the_ffi_crate_builds_no_rust_libraryrefuses a crate type that turns LTO off;the_fuzzer_compiles_the_ffi_crate_with_its_dependenciesholds the fuzzer's dependencies and features to the crate's, since the fuzz build only runs nightly.
Measured
macOS arm64, same commit, fresh target directory each, capi on:
| before | after | |
|---|---|---|
liboffline_protocol_uniffi.a | 137,949,536 | 23,393,288 |
liboffline_protocol_uniffi.dylib | 11,534,416 | 10,932,208 |
| exported C and UniFFI functions | 482 | 482 |
| build time / peak memory | 1m46 / 1.3 GB | 2m45 / 2.1 GB |
The static library is what the iOS framework and the npm package carry, so that is where nearly all of the win lands. The iOS and Android numbers will be read off the first release artifacts built this way.
Verified locally
cargo fmt,cargo clippy --workspace -- -D warnings, clippy without the C binding,cargo test --workspace --lib, rustdoc under-D warnings.- The uniffi crate's 263 unit tests all still run: it never had a doctest, so dropping the rlib loses none.
- The C consumer check (shared, static, exchange, quick start) and
scripts/check-c-library.sh macos-arm64against the LTO release dylib. - The Python suite against the LTO release dylib: 1124 passed, 4 skipped.
- Both guards negative-controlled six ways.
- The fuzzer: every seed runs, and
cargo +nightly fuzz run --sanitizer nonefor 60 s on macOS ran 1.4 million inputs with coverage rising to 2015 edges. Fuzzing on macOS did not link before this change;fuzz.ymlanddocs/bridges/c.mdnow say so.
Not covered here
fuzz.ymlhas never run. I will dispatch it on this branch.- The mobile profile (opt-level and panic strategy) is a separate PR: no build has ever used
minisize, while six documents say the mobile artifact shipspanic = "abort". - A Rust consumer of the crate from crates.io (0.29.0 has none) can no longer depend on it.