Skip to content

[DRAFT] Use arena allocator when exporting goto binaries #4210

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AlexanderPortland
Copy link
Contributor

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 contains Irep structs which can each recursively contain multiple Vecs of even more Ireps, 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 proper hashbrown::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.

@AlexanderPortland AlexanderPortland changed the title [DRAFTUse arena allocator when exporting goto binaries [DRAFT] Use arena allocator when exporting goto binaries Jul 7, 2025
@github-actions github-actions bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant