Skip to content

Use bit sets to simplify large marker DNFs - #22640

Closed
charliermarsh wants to merge 2 commits into
charlie/direct-marker-transformfrom
charlie/marker-dnf-bitsets
Closed

charliermarsh wants to merge 2 commits into
charlie/direct-marker-transformfrom
charlie/marker-dnf-bitsets

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Summary

We convert decision diagrams to disjunctive normal form (DNF) when rendering markers, then simplify the result by comparing clauses and removing redundant terms. When there are many conflicting extras, the DNF can contain a lot of clauses, and those comparisons can be expensive (see #21954).

This PR makes the comparisons cheaper for larger DNFs. We assign each distinct marker term an integer and represent each clause as a bit set, so we can compare sets instead of repeatedly comparing full marker expressions. We keep the same removal order, since removing one term can affect later comparisons.

For small DNFs, clauses with repeated terms, or expressions that would need a bit-set index larger than 32 MiB, we fall back to the existing simplifier. We also use indexed term lookups for sparse clauses.

We still build the DNF and perform up to a quadratic number of clause comparisons. Boolean operations that already avoid DNF and environment-only conflict markers that are narrowed before DNF conversion do not use this path.

Large conflict sets produce marker DNFs with many clauses. Simplification repeatedly compares their terms, including string and version values. Intern those terms and represent clauses as bit sets so we can compare integer IDs and machine words instead.

Keep direct comparisons for small DNFs and use indexed term lookups for sparse clauses. Cap the dense bit-set index at 32 MiB and fall back to the linear algorithm for larger indexes or repeated terms within a clause. Terms and clauses are eliminated in the same order, so earlier removals affect later comparisons and serialized markers remain consistent.

This reduces the cost of each comparison; DNF materialization and the quadratic number of clause comparisons remain. Related to #21954.
@charliermarsh
charliermarsh marked this pull request as ready for review October 16, 2026 15:58
@codspeed

codspeed Bot commented Oct 16, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚡ 25 improved benchmarks
❌ 1 regressed benchmark
✅ 93 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation imbibe_marker_no_conflicts[0] 287.4 ns 398.5 ns -27.88%
⚡ Simulation marker_to_dnf_conflicting_extras[32] 4,084.4 ms 73.6 ms ×56
⚡ Simulation imbibe_and_format_marker_environment_only[32] 4,122.8 ms 74.3 ms ×55
⚡ WallTime imbibe_and_format_marker_environment_only[32] 235.4 ms 4.3 ms ×54
⚡ WallTime marker_to_dnf_conflicting_extras[32] 233.8 ms 4.3 ms ×54
⚡ Simulation imbibe_and_format_marker_conflict_dependent[32] 11,610.8 ms 297.1 ms ×39
⚡ WallTime imbibe_and_format_marker_conflict_dependent[32] 633.3 ms 16.8 ms ×38
⚡ Simulation marker_to_dnf_conflicting_extras[16] 71.3 ms 3.2 ms ×23
⚡ Simulation imbibe_and_format_marker_environment_only[16] 72.4 ms 3.3 ms ×22
⚡ WallTime marker_to_dnf_conflicting_extras[16] 3,900.5 µs 182.5 µs ×21
⚡ Simulation imbibe_and_format_marker_conflict_dependent[16] 227.3 ms 10.9 ms ×21
⚡ WallTime imbibe_and_format_marker_environment_only[16] 3,896.6 µs 189.3 µs ×21
⚡ WallTime imbibe_and_format_marker_conflict_dependent[16] 11,930.5 µs 609.5 µs ×20
⚡ WallTime imbibe_and_format_marker_conflict_dependent[4] 6.5 µs 3.3 µs +95.72%
⚡ Simulation marker_to_dnf_sparse_clauses[512] 150 ms 89.4 ms +67.73%
⚡ Simulation imbibe_and_format_marker_conflict_dependent[4] 169 µs 106.3 µs +59.09%
⚡ Simulation marker_to_dnf_sparse_clauses[128] 9 ms 5.7 ms +57.63%
⚡ WallTime marker_to_dnf_sparse_clauses[512] 9.6 ms 6.8 ms +42.4%
⚡ WallTime marker_to_dnf_sparse_clauses[128] 614.7 µs 468 µs +31.34%
⚡ WallTime imbibe_marker_no_conflicts[0] 7 ns 6 ns +16.67%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing charlie/marker-dnf-bitsets (a1409c6) with charlie/direct-marker-transform (9f461ef)

Open in CodSpeed

Footnotes

  1. 54 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@charliermarsh

Copy link
Copy Markdown
Member Author

Superseded by #22651.

charliermarsh added a commit that referenced this pull request Oct 18, 2026
We extract marker DNF directly from the decision diagram with a memoized
ISOP algorithm, instead of enumerating paths and simplifying the
resulting clauses. This avoids expensive clause comparisons for markers
with many conflicting extras and replaces #22640, #22641, and #22642.

Marker strings can change, but remain logically equivalent. We also fix
Python-version complexification to preserve the variable ordering
required by the traversal.

Warm medians in microseconds, comparing #22642 (`21f4b07`) with this PR
(`f9df0b8`):

| Operation | #22642 | This PR | Speedup |
| ---------------------------------------- | ------: | ------: | ------:
|
| Two-clause DNF | 0.606 | 0.433 | 1.4× |
| Mixed Python/platform DNF | 1.125 | 0.658 | 1.7× |
| Sparse DNF, 512 clauses | 8,010.3 | 65.0 | 123× |
| Conflict DNF, 32 extras | 2,959.6 | 46.0 | 64× |
| Conflict-dependent formatting, 32 extras | 8,690.4 | 109.9 | 79× |

Measured on a pinned AMD EPYC Linux core with Rust 1.99.0-dev / Ohm,
using 48 samples across three cohorts. Input construction is untimed.
These are warm-interner microbenchmarks, not end-to-end resolution
timings. The first mixed conversion in a fresh process is slightly
slower: 16.6 µs → 20.3 µs.

This branch was previously deployed

1 inactive deployment
automations — a1409c67 Deployed Oct 16, 2026 by charliermarsh via review / security review #51357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants