Terminating the process with `panic` takes longer with `panic="abort"`?

In my debug builds panic terminates the process right away, it takes no time.

In release builds panic takes a second or two before the process termintes.

Normally who cares, but I have a weird test setup where I run my executable on about a hundred files. Most of them panic today.

As I fix the tests there will be no panics, but today running this test suite spends maybe half a minute on these post-panic delays.

I investigated this issue a little bit and it turns out it's this line in my Cargo.toml that causes the issue:

[profile.release]
panic = "abort"

With the default panic setting (unwind?) the processes terminate fast.

Is this expected? How can aborting the process take longer than aborting right away on panic?

How are you measuring this? Can you show your repro steps?

Repro:

  • Clone GitHub - fir-lang/fir: Fir programming language, make debug and release builds with cargo build.
  • export FIR_ROOT=<repo directory>
  • Then in the repo directory:
    time ./target/debug/fir compiler/Parser.fir -- tests/AndOrEvaluation.fir
    time ./target/release/fir compiler/Parser.fir -- tests/AndOrEvaluation.fir
    

Outputs on my system with the latest Rust stable:

./target/debug/fir compiler/Parser.fir -- tests/AndOrEvaluation.fir  0.24s user 0.03s system 99% cpu 0.268 total
./target/release/fir compiler/Parser.fir -- tests/AndOrEvaluation.fir  0.04s user 0.02s system 5% cpu 1.115 total

Abort may be causing the system to capture a core dump, while a panic unwind past main will just exit with status 101.

7 Likes

That's it, thanks.

Can you also check panic_immediate_abort?

error: failed to parse manifest at `/home/omer/fir/fir/Cargo.toml`

Caused by:
  `panic` setting of `panic_immediate_abort` is not a valid setting, must be `unwind` or `abort`

It is not a strategy, it is a compiler flag!

cargo +nightly build -Z build-std-features=panic_immediate_abort

I was under the impression you also had to instruct the compiler to build core/alloc/std? For example, instead of passing the flags explicitly to cargo/rustc, one can add the following tables to ~/.cargo/config.toml:

[profile.release]
lto = true
panic = 'abort'
strip = true

[unstable]
build-std = ["core"] # or ["alloc"] or ["std"]
build-std-features = ["panic_immediate_abort"]

Then build it by running cargo +nightly build --release. Admittedly I have almost no experience using Cargo's unstable features, so perhaps passing build-std-features is sufficient.

2 Likes

In any case, that's still going through intrinsics::abort, so the system core dump will remain.

3 Likes