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
T-CBMCIssue related to an existing CBMC issueT-UserTag user issues / requests[C] BugThis is a bug. Something isn't working.[E] PerformanceTrack performance improvement (Time / Memory / CPU)
Thank you for the test case. This is a great example of a performance problem that shouldn't exist, and we'll have to investigate.
(There are several things in how we translate Rust code down to CBMC's IR that CBMC hasn't yet been "tuned" for. Vectors are a current focus area, but this seems like another one that likely has a very addressable cause...)
(BTW: Since you use += the + accumulator is not needed. I don't think this will change anything about performance here but these two are not currently equivalent code.)
Thank you for the test case. This is a great example of a performance problem that shouldn't exist, and we'll have to investigate.
(There are several things in how we translate Rust code down to CBMC's IR that CBMC hasn't yet been "tuned" for. Vectors are a current focus area, but this seems like another one that likely has a very addressable cause...)
Thank you. I've also noticed issues with vectors. Is it worthwhile to submit an issue there as well?
(BTW: Since you use += the + accumulator is not needed. I don't think this will change anything about performance here but these two are not currently equivalent code.)
fold.log:Verification Time: 35.88157s
fold.log: Maximum resident set size (kbytes): 3459548
for.log:Verification Time: 11.837213s
for.log: Maximum resident set size (kbytes): 532692
for_iter.log:Verification Time: 11.500173s
for_iter.log: Maximum resident set size (kbytes): 592848
So the fold version seems to be at least 3X slower, and consumes ~6X more memory.
It seems that the difference in performance is caused by iterators. Comparing these two versions, which are identical expect for the .iter() used in the second, Kani performs much worse on the second:
Without .iter():
pubfnarray_sum_for_iter1(x:[usize;100]) -> usize{letmut accumulator:usize = 0;for i in x {
accumulator += i;}
accumulator
}
Verification Time: 11.509705s
Maximum resident set size (kbytes): 592648
With .iter():
pubfnarray_sum_for_iter2(x:[usize;100]) -> usize{letmut accumulator:usize = 0;for i in x.iter(){
accumulator += i;}
accumulator
}
Verification Time: 38.08861s
Maximum resident set size (kbytes): 3495444
The changes hinted at in #1226 (comment) also bring down time for array_sum_fold_proof to the same as the other two cases (i.e., approximately 11 seconds).
T-CBMCIssue related to an existing CBMC issueT-UserTag user issues / requests[C] BugThis is a bug. Something isn't working.[E] PerformanceTrack performance improvement (Time / Memory / CPU)
Activity
tedinski commentedon Nov 1, 2022
Thank you for the test case. This is a great example of a performance problem that shouldn't exist, and we'll have to investigate.
(There are several things in how we translate Rust code down to CBMC's IR that CBMC hasn't yet been "tuned" for. Vectors are a current focus area, but this seems like another one that likely has a very addressable cause...)
(BTW: Since you use
+=the+ accumulatoris not needed. I don't think this will change anything about performance here but these two are not currently equivalent code.)weaversa commentedon Nov 1, 2022
Thank you. I've also noticed issues with vectors. Is it worthwhile to submit an issue there as well?
Quite right! I made the correction.
tedinski commentedon Nov 1, 2022
We are tracking some Vec issues here: #1676
Another thought I want to write down before I forget: I wonder if
for i in xwould display different performance from the other two implementations...zhassan-aws commentedon Nov 1, 2022
I added a for-iter version:
and I got the following numbers with 33e226b:
So the fold version seems to be at least 3X slower, and consumes ~6X more memory.
zhassan-aws commentedon Nov 1, 2022
It seems that the difference in performance is caused by iterators. Comparing these two versions, which are identical expect for the
.iter()used in the second, Kani performs much worse on the second:Without
.iter():With
.iter():tedinski commentedon Nov 1, 2022
I confess I thought those two would be the same. What does
fordesugar to then?Oh wait, is it doing
into_iter()?zhassan-aws commentedon Nov 1, 2022
Yes,
forby default usesinto_iter():https://doc.rust-lang.org/std/iter/index.html#for-loops-and-intoiterator
tedinski commentedon Nov 1, 2022
Well that brings to mind another option:
x.into_iter().fold(0, |accumulator, current| accumulator + current)zhassan-aws commentedon Nov 1, 2022
Indeed, this version (slightly modified from yours due to a warning) performs the same as the
for i in xversion:tautschnig commentedon Nov 9, 2022
The changes hinted at in #1226 (comment) also bring down time for
array_sum_fold_proofto the same as the other two cases (i.e., approximately 11 seconds).Add test for model-checking#1823