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
Performance drastically differs across two string indexing operations #3328
CBMC's memory usage exceeds 24 GB after running for 2 minutes. These are the last few lines it prints before running out of memory:
Runtime Symex: 44.498s
size of program expression: 889131 steps
slicing removed 550833 assignments
Generated 63496 VCC(s), 27179 remaining after simplification
Runtime Postprocess Equation: 0.942692s
Passing problem to propositional reduction
converting SSA
Runtime Convert SSA: 22.1197s
For the commented-out version of the slice indexing operation (which is supposedly equivalent), verification is successful in ~26 seconds with less than 1 GB of memory usage:
$ kani str_slice_perf.rs
...
Runtime Symex: 2.71987s
size of program expression: 73171 steps
slicing removed 55203 assignments
Generated 3677 VCC(s), 2301 remaining after simplification
Runtime Postprocess Equation: 0.0965727s
Passing problem to propositional reduction
converting SSA
Runtime Convert SSA: 0.708747s
...
SUMMARY:
** 0 of 581 failed (16 unreachable)
VERIFICATION:- SUCCESSFUL
Verification Time: 25.568632s
let s_trunc = &s[..trunc_len];
...let ch = s[char_start..].chars().next().unwrap();
which means that Kani will need to recurse as it can't establish that either indexing won't panic. (I'm not even convinced slice_error_fail_rt is safe (what if end == s.len()?), but that's a matter for our standard library verification effort.)
I believe we should look at stubbing out slice_error_fail_rt (and possibly other verbose error handling in the standard library) as, for Kani's purpose, it should be no different than directly using panic!.
Activity
zhassan-aws commentedon Jul 6, 2024
To double check that the two versions are equivalent, I wrote this harness:
which successfully verifies (up to 3 bytes). Beyond 3 bytes, it runs out of memory.
tautschnig commentedon Aug 5, 2024
The performance problem is solely caused by the error-handling path: Quoting from
https://github.com/rust-lang/rust/blob/4d48a6be74d46304cacb93cb8eb60d70d733b862/library/core/src/str/traits.rs#L537-L543:
where
slice_error_failresolves toslice_error_fail_rtat runtime, see https://github.com/rust-lang/rust/blob/4d48a6be74d46304cacb93cb8eb60d70d733b862/library/core/src/str/mod.rs#L82-L115. Notably, this includeswhich means that Kani will need to recurse as it can't establish that either indexing won't panic. (I'm not even convinced
slice_error_fail_rtis safe (what ifend == s.len()?), but that's a matter for our standard library verification effort.)I believe we should look at stubbing out
slice_error_fail_rt(and possibly other verbose error handling in the standard library) as, for Kani's purpose, it should be no different than directly usingpanic!.zhassan-aws commentedon Aug 5, 2024
Thanks for investigating this @tautschnig. This sounds similar to #3030 (comment). Seems we need a general solution for error-handling paths.
zhassan-aws commentedon Aug 26, 2025
As of 8b8b897, memory usage for the original program remains under ~5 GB and verification succeeds in ~4 minutes.
feliperodri commentedon Nov 5, 2026
Fixed in 8b1c1ec:
core::str::slice_error_failis now hooked as a panic (hooks.rs:431). Verified on main: the original harness passes (repro 3328-1).