Repository navigation
miniBDD: a hash table for the computed table of apply - #9639
Merged
kroening merged 2 commits intoDec 4, 2026
Merged
Conversation
The hash of the unique table's keys mixes var, low and high by multiplying the value so far by 0x9e3779b1 and adding the next component. Move this step into a helper, so that further hash tables can use the same scheme and the explanation of the constant lives in one place. The hash values are unchanged. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
mini_bdd_applyt consults its computed table, a std::map from pairs of node numbers to results, at every step. Once the unique table became a hash table (diffblue#9182), the lookups in this tree were the largest part of the run time of random BDD operations (about a quarter, with perf). Make it a std::unordered_map, hashing the pair with combine_hash. Measured with a stand-alone driver that applies random and, or, xor, not, equivalence, exists and restrict operations to a pool of BDDs, three seeds each (x86-64, g++ 13.3 -O2), before -> after: - 8 variables, 1,000,000 operations: 4.03-4.08 s -> 3.59-3.64 s (1.12x) - 12 variables, 200,000 operations: 26.4-29.2 s -> 21.5-23.5 s (1.24x) - 16 variables, 20,000 operations: 43.7-47.7 s -> 37.2-40.8 s (1.17x) - 4 variables, 2,000,000 operations: 1.23 s -> 1.27-1.28 s (3% slower): each operation creates its own computed table, and allocating the buckets of a hash table costs more than it saves for a handful of entries. The node numbers of all results and the node counts are the same before and after, and the driver is clean under ASan and UBSan. The computed table of restrict, a std::map keyed by node number, is consulted far less often: a hash table there made no measurable difference on these workloads, and was 3% slower on the smallest one, so it stays a tree. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the apply-cache optimization.
No open issues 🎉
What changed in this PR
Speeds up miniBDD’s Boolean operations by extending the earlier unique-table hash optimization to apply’s computed table.
Changes:
- Replaces apply’s
std::mapcache withstd::unordered_map. - Extracts a shared hash helper while preserving existing unique-table hash values.
- Leaves restrict’s computed table unchanged.
| File | Description |
|---|---|
src/solvers/bdd/miniBDD/miniBDD.cpp |
Adds node-pair hashing, switches apply’s cache container, and shares hash-combining logic. |
Review effort: Balanced
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9639 +/- ##
===========================================
- Coverage 81.34% 81.34% -0.01%
===========================================
Files 1727 1727
Lines 191752 191753 +1
Branches 73 73
===========================================
- Hits 155988 155986 -2
- Misses 35764 35767 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kroening
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #9182.
mini_bdd_applytlooks up its computed table, astd::mapfrom pairs of node numbers to results, at every step. After #9182, lookups in this tree took about a quarter of the run time of random BDD operations (measured with perf). This PR makes the table astd::unordered_map.The first commit moves the multiply-and-add step of the unique table's hash into a helper,
combine_hash, which the new hash table uses as well. The hash values do not change.Measured with a stand-alone driver that applies random and, or, xor, not, equivalence, exists and restrict operations to a pool of BDDs. Each row is three seeds, on x86-64 with g++ 13.3 -O2:
The smallest case gets slower because each operation creates its own computed table, and for a table of only a few entries, allocating the hash table's buckets costs more than the faster lookups save. Node numbers and node counts are identical before and after, and the driver runs clean under ASan and UBSan.
The computed table of
restrictstays a tree. It is consulted far less often: a hash table there made no measurable difference on these workloads, and was 3% slower on the smallest one.unitandregression/cbmc(with--validate-goto-model --validate-ssa-equation) pass.