Repository navigation
miniBDD: use a hash table for the unique table - #9182
Merged
tautschnig merged 3 commits intoDec 4, 2026
Merged
tautschnig merged 3 commits into
tautschnig merged 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #9182 +/- ##
========================================
Coverage 81.34% 81.35%
========================================
Files 1727 1727
Lines 191715 191752 +37
Branches 73 73
========================================
+ Hits 155950 155997 +47
+ Misses 35765 35755 -10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kroening
force-pushed
the
kroening/minibdd-unordered-unique-table
branch
from
November 28, 2026 20:30
a94f8b2 to
a955fb8
Compare
mini_bdd_mgrt::mk looks up every candidate node in the unique table (reverse_map) before creating it, so this lookup is on the hot path of every BDD operation. It was a std::map (a balanced tree), giving O(log n) pointer-chasing comparisons per node. Switch it to std::unordered_map with a hash over (var, low, high). Profiling the ebmc BDD model checker showed mini_bdd_mgrt::mk accounting for about a third of the run time, dominated by the tree traversal. On the 50 smallest HWMCC08 instances (ebmc --bdd, on top of the early variable quantification of diffblue/hw-cbmc#1801, 20s timeout), this is a 1.45x speedup on the instances solved by both, with no change in results (all still agree with the ABC reference).
The comment said that 0x9e3779b1 is the 32-bit approximation of 2^32 / phi and that the constant and the scheme are those of Boost's hash_combine and of Knuth's multiplicative hashing. 2^32 / phi rounds to 0x9e3779b9 (2654435769); 0x9e3779b1 (2654435761) is the prime closest to it. Boost's hash_combine (of which src/goto-programs/graphml_witness.h has a copy) uses 0x9e3779b9 with shifts and exclusive or, and Knuth's multiplicative hashing keeps the high bits of the product, while here std::unordered_map gets the whole value. The constant itself is fine. Also document reverse_key_hasht with a Doxygen comment. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The existing miniBDD scenarios reach the unique table only through the Boolean operators, and none checks that released nodes are freed: removing the push onto the free list in mini_bdd_nodet::remove_reference leaves them passing. The new scenario checks that equivalent functions share a node over several rounds that reuse released nodes, that the number of nodes returns to its baseline once all results are released, that mk returns the existing node for the same arguments, and that a reused node is found under its new arguments only, and evaluates the results. It fails when remove_reference does not free the node, does not erase its key, or when mk does not enter a reused node, and passes both with the hash table and with the std::map that it replaced. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig
force-pushed
the
kroening/minibdd-unordered-unique-table
branch
from
December 3, 2026 23:14
a955fb8 to
1a44d84
Compare
tautschnig
approved these changes
Dec 4, 2026
tautschnig
enabled auto-merge
December 4, 2026 00:10
5 tasks done
kroening
pushed a commit
that referenced
this pull request
Dec 4, 2026
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 (#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>
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.
Changes
mini_bdd_mgrt::mkconsults the unique table (reverse_map) for everycandidate node before creating it, so this lookup is on the hot path of every
BDD operation. It was a
std::map(a balanced tree), i.e. O(log n)pointer-chasing comparisons per node.
This switches the unique table to
std::unordered_map, with a hash over(var, low, high).reverse_keytgainsoperator==and a hash functor; itsnow-unused
operator<is removed.Motivation
Profiling the
ebmc --bddmodel checker (on top of the early variablequantification of diffblue/hw-cbmc#1801) showed
mini_bdd_mgrt::mkaccountingfor roughly a third of the run time, dominated by the
std::maptreetraversal. The unique table is a hash table in essentially every production
BDD package for this reason.
Performance
ebmc --bddon the 50 smallest HWMCC08 AIGER instances, on top ofdiffblue/hw-cbmc#1801, 20s timeout per instance, Apple Silicon. Two builds
that differ only by this commit in the cbmc submodule:
All answers agree with the ABC reference column in
hwmcc08results.csv.Representative per-instance improvements:
visarbiter5.34s → 3.34s,eijkS208o4.95s → 3.70s,pdtvisminmax02.75s → 1.87s.Testing
unit "[miniBDD]"andunit "[solver]"pass. The change does not alter BDDsemantics (the unique table is a lookup structure only); the HWMCC08
cross-check against the ABC reference shows no change in results.