Skip to content

Cache clause differences when simplifying large marker DNFs - #22641

Closed
charliermarsh wants to merge 1 commit into
charlie/marker-dnf-bitsetsfrom
charlie/marker-dnf-candidates
Closed

charliermarsh wants to merge 1 commit into
charlie/marker-dnf-bitsetsfrom
charlie/marker-dnf-candidates

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Summary

When simplifying a DNF, we can compare each clause with the others for every term we consider removing. For markers with many clauses that reuse the same terms, as with conflicting extras, we can end up computing the same differences repeatedly.

This PR caches the relevant differences for each clause and reuses them as we check its terms. We skip candidates that cannot justify a removal, and update the cached differences when a term is removed so later comparisons see the updated clause.

We use this path for large DNFs with relatively few distinct terms. Smaller or sparser expressions continue to use indexed comparisons. The DNF still needs to be created, and the number of clause comparisons can still be quadratic.

@codspeed

codspeed Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ 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

⚡ 7 improved benchmarks
❌ 2 regressed benchmarks
✅ 110 untouched benchmarks
⏩ 54 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ ⚠️ Simulation discover_workspace_from_all_members_with_excludes 142.2 ms 163.9 ms -13.22%
❌ ⚠️ Simulation discover_workspace_from_all_members 140.1 ms 153.8 ms -8.89%
⚡ WallTime imbibe_and_format_marker_conflict_dependent[32] 16.8 ms 5.7 ms ×2.9
⚡ WallTime marker_to_dnf_conflicting_extras[32] 4.3 ms 1.9 ms ×2.2
⚡ WallTime imbibe_and_format_marker_environment_only[32] 4.3 ms 1.9 ms ×2.2
⚡ Simulation imbibe_and_format_marker_conflict_dependent[32] 297.1 ms 150.7 ms +97.22%
⚡ Simulation marker_to_dnf_conflicting_extras[32] 73.6 ms 48.2 ms +52.69%
⚡ Simulation imbibe_and_format_marker_environment_only[32] 74.3 ms 48.9 ms +51.95%
⚡ Simulation imbibe_marker_no_conflicts[0] 398.5 ns 287.4 ns +38.66%

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-candidates (cceb622) with charlie/marker-dnf-bitsets (a1409c6)

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. ↩

Large marker DNFs often reuse a small set of terms across many clauses. The indexed simplifier recomputes the difference between two clauses for each term it considers removing. Compute viable differences once per clause and reuse them across those term checks.

Count missing terms first to discard candidates that cannot justify a removal, then update the cached differences after each removal so later checks use the surviving terms. Enable this path only when enough clauses reuse relatively few terms; smaller and sparser DNFs retain direct comparisons. Differential tests check that both paths produce the same ordered output as the linear simplifier.
@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 — cceb6223 Deployed Oct 16, 2026 by charliermarsh via review / security review #51368
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.

2 participants