You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Binary size regression of panic=immediate-abort since nightly-2025-09-24 #147257
-Cpanic=immediate-abort was added in #146317 to replace -Zbuild-std-features=panic_immediate_abort.
However, we've observed a double-digit binary size regression with that:
Both core and std are increased, while gimli, miniz_oxide, and addr2line stay roughly the same.
It seems that -Cpanic=immediate-abort does work to some degree.
We had a similar issue with our baremetal ARM executable (binary grew 25% going from nightly-2025-09-23 to nightly-2025-09-24 and after converting from the build-std-feature to rustflags with the unstable panic strategy). But it turned out to be an issue with Cargo and how we placed those flags into config.toml files for consumption. Don't know if that will help for your Android app builds (it is unclear to me how the Corrosion tool works). We thought we had the exact same experience, but it turned out to be a bit of Cargo user error.
use anyhow::Result;use jni::JNIEnv;use jni::objects::JByteBuffer;use jni::sys::jint;use jni_fn::jni_fn;use std::ptr::slice_from_raw_parts_mut;#[jni_fn("com.hippo.ehviewer.client.parser.UserConfigParser")]pubfnparseFavCat(mutenv:JNIEnv,buffer:JByteBuffer) -> jint{dummy(&mut env, buffer)}fndummy<'local>(env:&JNIEnv,buffer:JByteBuffer<'local>) -> jint{matchderef_mut_direct_bytebuffer(env, buffer){Ok(_) => 0,
_ => 1,}}fnderef_mut_direct_bytebuffer<'local>(env:&JNIEnv,buffer:JByteBuffer<'local>,) -> Result<&'localmut[u8]>{let ptr = env.get_direct_buffer_address(&buffer)?;let cap = env.get_direct_buffer_capacity(&buffer)?;// SAFETY: jni contract, buffer must alive through native call.Ok(unsafe{&mut*slice_from_raw_parts_mut(ptr, cap)})}
At which point it's pretty clear to me that the problem is the anyhow backtrace code. I'm going to minimize a bit more, but at this point I'm a bit confused that the backtrace code optimized away before.
I think that the problem here is that the standard library crate std has an on-by-default feature called backtrace which is disabled when -Zbuild-std-features=panic_immediate_abort is passed. This overriding of default features is documented: https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features
@FooIbar Can you confirm that adding -Zbuild-std-features= (which looks very silly) fixes this size regression?
@FooIbar Can you confirm that adding -Zbuild-std-features= (which looks very silly) fixes this size regression?
Ah, true! Adding -Zbuild-std-features= does fix the regression.
I think I've seen this trick somewhere (edit: found it google/bloaty#110 (comment)) before but totally forgot it.
Feel free to close this issue.
Since you're already using immediate-aborting panics, you might want to pass -Zbuild-std-features=optimize_for_size. Might make your code even smaller.
Activity
bjorn3 commentedon Oct 2, 2025
I wonder if the
panic = "abort"in https://github.com/FooIbar/EhViewer/blob/085e0938cba98a5e961431660d137d492b41c54a/app/src/main/rust/Cargo.toml#L37 overrides the-Cpanic=immediate-abort.FooIbar commentedon Oct 2, 2025
For reference building without
-Cpanic=immediate-abort:Both
coreandstdare increased, whilegimli,miniz_oxide, andaddr2linestay roughly the same.It seems that
-Cpanic=immediate-abortdoes work to some degree.Update:
I also tried removing the
panic = "abort"but that didn't work.saethlin commentedon Oct 2, 2025
Where do I run those commands?
AstralZebulon commentedon Oct 2, 2025
We had a similar issue with our baremetal ARM executable (binary grew 25% going from nightly-2025-09-23 to nightly-2025-09-24 and after converting from the build-std-feature to rustflags with the unstable panic strategy). But it turned out to be an issue with Cargo and how we placed those flags into config.toml files for consumption. Don't know if that will help for your Android app builds (it is unclear to me how the Corrosion tool works). We thought we had the exact same experience, but it turned out to be a bit of Cargo user error.
FooIbar commentedon Oct 3, 2025
For
cargo bloatto work with https://github.com/FooIbar/EhViewer/blob/085e0938cba98a5e961431660d137d492b41c54a/app/src/main/rust/Cargo.toml:It turns out it's not specific to Android, so I tweaked those commands so you don't need to set up the NDK:
I've also updated the numbers in the comments above with the updated commands.
saethlin commentedon Oct 3, 2025
I've minimized the crate to this:
At which point it's pretty clear to me that the problem is the anyhow backtrace code. I'm going to minimize a bit more, but at this point I'm a bit confused that the backtrace code optimized away before.
saethlin commentedon Oct 3, 2025
Yep, minimizes to this:
saethlin commentedon Oct 3, 2025
I think that the problem here is that the standard library crate
stdhas an on-by-default feature calledbacktracewhich is disabled when-Zbuild-std-features=panic_immediate_abortis passed. This overriding of default features is documented: https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features@FooIbar Can you confirm that adding
-Zbuild-std-features=(which looks very silly) fixes this size regression?FooIbar commentedon Oct 3, 2025
Ah, true! Adding
-Zbuild-std-features=does fix the regression.I think I've seen this trick somewhere (edit: found it google/bloaty#110 (comment)) before but totally forgot it.
Feel free to close this issue.
saethlin commentedon Oct 3, 2025
Since you're already using immediate-aborting panics, you might want to pass
-Zbuild-std-features=optimize_for_size. Might make your code even smaller.FooIbar commentedon Oct 3, 2025
Yeah I know that, but I'd prefer speed over size.