Skip to content

Share DNF simplification across clause representations - #22642

Closed
charliermarsh wants to merge 4 commits into
charlie/marker-dnf-candidatesfrom
charlie/shared-dnf-simplifier
Closed

charliermarsh wants to merge 4 commits into
charlie/marker-dnf-candidatesfrom
charlie/shared-dnf-simplifier

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Summary

We currently have separate DNF simplification passes for direct comparisons, indexed comparisons, and cached clause differences. Each pass has to remove terms and clauses in the same order, since one removal can affect the next.

This PR shares the ordered removal pass through a private trait for clause comparisons. Small markers still compare expressions directly, without interning their terms. Larger markers use the existing bit sets and cached differences. Each representation keeps its own removal state, and the caching choice stays inside the indexed implementation. Redundant clauses use indexed Boolean flags, with inline storage for small DNFs, so membership checks remain constant-time. The original linear simplifier is compiled only for tests, where it checks the exact ordered output of both representations.

We retain the existing indexing thresholds, repeated-term fallback, and index memory limit. DNF creation and quadratic clause comparisons remain.

Native Criterion measurements on a quiet Linux devbox compared the original patch-equivalent parent (6e34068) with the original head (f25b35f). Both used uv's allocator and the same Ohm 1.98.1 compiler and profiling profile. Negative changes mean less time:

Operation Parent This PR Change
to_dnf, two clauses 0.849 µs 0.863 µs +1.6%
to_dnf, mixed clauses 1.546 µs 1.583 µs +2.4%
to_dnf, 32 conflicting extras 4.138 ms 3.972 ms −4.0%
to_dnf, 512 sparse clauses 8.753 ms 8.735 ms −0.2%
imbibe and format, conflict-dependent marker [4] 6.719 µs 6.452 µs −4.0%
imbibe and format, conflict-dependent marker [32] 12.364 ms 12.055 ms −2.5%

Each value is the median of three process estimates, with 20 Criterion samples per run and versions interleaved on the same pinned core. Diagrams are built before timing. These short runs do not reliably distinguish changes of a few percent, and operation measurements do not establish a lock or export speedup.

@codspeed

codspeed Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 4 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
❌ 4 regressed benchmarks
✅ 108 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%
❌ WallTime marker_to_dnf_conflicting_extras[4] 2.3 µs 2.5 µs -6.4%
❌ WallTime marker_to_dnf_platform_specific_python_versions 910 ns 961 ns -5.31%
❌ WallTime imbibe_and_format_marker_environment_only[4] 3 µs 3.2 µs -5.17%
⚡ Simulation imbibe_and_format_marker_conflict_dependent[16] 11 ms 6.2 ms +77.55%
⚡ Simulation marker_to_dnf_conflicting_extras[16] 3.2 ms 2 ms +61.06%
⚡ Simulation imbibe_and_format_marker_environment_only[16] 3.4 ms 2.2 ms +55.93%
⚡ WallTime imbibe_and_format_marker_conflict_dependent[16] 592.2 µs 452.9 µs +30.78%
⚡ WallTime imbibe_and_format_marker_environment_only[16] 185.9 µs 152.3 µs +22.05%
⚡ ⚠️ Simulation discover_workspace_from_all_members 153.8 ms 140.8 ms +9.25%
⚡ Simulation marker_to_dnf_sparse_clauses[128] 5.8 ms 5.4 ms +6.02%

Tip

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


Comparing charlie/shared-dnf-simplifier (21f4b07) with charlie/marker-dnf-candidates (cceb622)

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
charliermarsh force-pushed the charlie/marker-dnf-candidates branch from 86706d3 to cceb622 Compare October 16, 2026 17:07
@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 — 21f4b07e Deployed Oct 16, 2026 by charliermarsh via review / security review #51378
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.

1 participant