-
Notifications
You must be signed in to change notification settings - Fork 99
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
Performance depends in surprising ways on struct definitions #1958
Comments
In
(which eventually controls the branch taken by
I don't know why such different code is generated, but it seems that CBMC does not currently succeed in constant-propagating the latter case. I'll see what can be done about this on the CBMC side, but you might also want to investigate why Kani produces such different code here. |
This fixes a bits/bytes confusing, resulting in missed optimisations of byte_extract(byte_update(...)) nestings when the byte_extract was at an offset higher than the update. Found while debugging model-checking/kani#1958.
Hmm, perhaps the reason for the above code is that the element at offset 0 is padding:
I have no idea why Kani inserts padding at the beginning of this struct, but this at least explains why it isn't possible to use a member access here. Anyway, diffblue/cbmc#7411 fixes the problem of the missing simplification/constant-propagation on the CBMC side. |
Amazing - thanks @tautschnig for taking a look and quickly coming up with a fix! I'll check with the rest of the Kani team about the struct padding and open an issue if it's unexpected behavior. |
This fixes a bits/bytes confusing, resulting in missed optimisations of byte_extract(byte_update(...)) nestings when the byte_extract was at an offset higher than the update. Found while debugging model-checking/kani#1958.
We should only close this once the issue has been fixed and a test has been added to our regression. |
It looks like we do some pretty worst-case accesses to discriminants: kani/kani-compiler/src/codegen_cprover_gotoc/codegen/rvalue.rs Lines 582 to 595 in 886618c
It could be this is in the category of "things we translate poorly" for CBMC? |
I don't know how hard it would be to do better than this, but the current approach will quite heavily rely on CBMC's capability to rewrite and simplify expressions. Producing something more high-level seems worth investigating. |
Subtle differences in the definitions of structs---even when data of that type is never created---excessively affects Kani's performance.
I tried this code:
using the following command line invocations:
with Kani v0.16.0 (commit #55ba7d64) and CBMC v5.71.0.
I expected to see this happen: the time it takes to verify
does not depend on the instantiation of the type parameter
T
.Instead, this happened: the time it takes varies greatly with what
T
is instantiated with.It takes >10s if
T
is instantiated withErr2
:It takes <1s if
T
is instantiated withErr3
:Furthermore, performance also depends on surprising ways on the type
Expr
. For example, say we add another variant:Now,
slow_harness1
is actually faster than before - it takes less than 1s. However, if we instead tweak the new variant by dropping one of the arguments, performance is much worse (40s):The text was updated successfully, but these errors were encountered: