Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow performance with the Display trait #1996

Closed
zhassan-aws opened this issue Dec 13, 2022 · 2 comments · Fixed by #2301
Closed

Slow performance with the Display trait #1996

zhassan-aws opened this issue Dec 13, 2022 · 2 comments · Fixed by #2301
Assignees
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Performance Track performance improvement (Time / Memory / CPU) T-CBMC Issue related to an existing CBMC issue

Comments

@zhassan-aws
Copy link
Contributor

I tried this code:

use std::fmt::Display;

enum Foo {
    A(String),
    B(String),
}

impl Display for Foo {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let s = match self {
            Foo::A(s) => format!("A.{s}"),
            Foo::B(s) => format!("B.{s}"),
        };
        write!(f, "{s}")?;
        Ok(())
    }
}

#[kani::proof]
#[kani::unwind(6)]
fn fast() {
    let a = Foo::A(String::from("foo"));
    let s = match a {
        Foo::A(s) => format!("A.{s}"),
        Foo::B(s) => format!("B.{s}"),
    };
    assert_eq!(s, "A.foo");
}

#[kani::proof]
#[kani::unwind(6)]
fn slow() {
    let a = Foo::A(String::from("foo"));
    let s = a.to_string();
    assert_eq!(s, "A.foo");
}

using the following command line invocation:

kani str_from.rs --harness fast
kani str_from.rs --harness slow

with Kani version: 71b9d0e

I expected to see this happen: Verification time is about the same for the two harnesses.

Instead, this happened: The fast harness completes in less than 4 seconds, but the slow harness runs for over 60 minutes without terminating (and consumes close to 6 GB of memory).

@zhassan-aws zhassan-aws added [C] Bug This is a bug. Something isn't working. [E] Performance Track performance improvement (Time / Memory / CPU) labels Dec 13, 2022
@zhassan-aws zhassan-aws changed the title Slow performance with the Display trait Slow performance with the Display trait Dec 13, 2022
@zhassan-aws zhassan-aws added [C] Feature / Enhancement A new feature request or enhancement to an existing feature. and removed [C] Bug This is a bug. Something isn't working. labels Dec 14, 2022
@tautschnig
Copy link
Member

The combination of diffblue/cbmc#7569 and diffblue/cbmc#7570 makes both harnesses complete in 2-3 seconds.

@tautschnig tautschnig added the T-CBMC Issue related to an existing CBMC issue label Mar 1, 2023
@zhassan-aws
Copy link
Contributor Author

Awesome! Thanks @tautschnig!

tautschnig added a commit to tautschnig/kani that referenced this issue Mar 17, 2023
- Re-enable tests that had to be disabled with the toolchain upgrade in
  model-checking#2149. Fixes model-checking#2286, fixes model-checking#2191.
- Do not generate non-NULL pointer constants. Together with the CBMC
  version update this avoids the need for an unwinding annotation in the
  mir-linker test. Fixes model-checking#1978.
- CBMC 5.79.0 ships simplifier improvements that enable constant
  propagation to avoid slow-down with the Display trait. Fixes model-checking#1996.
- CBMC 5.79.0 ships SMT back-end fixes. Fixes model-checking#2002.

Co-authored-by: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Performance Track performance improvement (Time / Memory / CPU) T-CBMC Issue related to an existing CBMC issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants