Skip to content

miniBDD: a hash table for the computed table of apply - #9639

Merged
kroening merged 2 commits into
diffblue:developfrom
tautschnig:kiro/minibdd-hashed-computed-table
Dec 4, 2026
Merged

kroening merged 2 commits into
diffblue:developfrom
tautschnig:kiro/minibdd-hashed-computed-table

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Follow-up to #9182. mini_bdd_applyt looks up its computed table, a std::map from 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 a std::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:

Variables Operations Before After
8 1,000,000 4.03–4.08 s 3.59–3.64 s 1.12×
12 200,000 26.4–29.2 s 21.5–23.5 s 1.24×
16 20,000 43.7–47.7 s 37.2–40.8 s 1.17×
4 2,000,000 1.23 s 1.27–1.28 s 3% slower

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 restrict stays 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.

unit and regression/cbmc (with --validate-goto-model --validate-ssa-equation) pass.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

tautschnig and others added 2 commits December 4, 2026 09:29
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>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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::map cache with std::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

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.34%. Comparing base (aef1c2b) to head (a101973).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kroening
kroening merged commit 2794d91 into diffblue:develop Dec 4, 2026
39 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants