[DRAFT] Use arena allocator when exporting goto binaries #4210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
A large portion (~7%) of our codegen time is spent simply deallocating the large
SymbolTable
struct that we generate when building each goto binary for CBMC. This ends up taking a while because the struct containsIrep
structs which can each recursively contain multiple Vecs of even moreIrep
s, requiring a lot of small allocations to be individually handled over and over again.Approach
This PR switches all data structures within Kani's binary generation to use a shared bump allocator (using the Bumpalo crate) that ensures all allocations we use while serializing a given binary remain in a single large region of memory. Once a given binary has been serialized, we can then easily deallocate all the memory it used at once.
As part of this change, we also replace the
LinearMap
used to represent named subs within an Irep with a properhashbrown::HashMap
.Issues
Based on manual testing there is currently a small memory leak (I think because the underlying vectors for the
BigInt
&BigUInt
types we use here) still use the global allocator and thus will not be deallocated with the memory arena. I'm looking into fixing this and improving code comments for the more involved changes, but wanted to make a draft PR to get preliminary performance results first.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.