Mitigate DNF explosion for depends field with disjoint disjunctions - #6831
Open
dra27 wants to merge 3 commits into
Open
Mitigate DNF explosion for depends field with disjoint disjunctions#6831dra27 wants to merge 3 commits into
dra27 wants to merge 3 commits into
Conversation
Member
Author
|
(original code is in #2968) |
kit-ty-kate
self-requested a review
December 8, 2025 13:47
rjbou
self-requested a review
December 8, 2025 13:47
A depends field of the form:
```
depends: [
"foo"
"bar"
("dep1" | "dep2")
("dep3" | "dep4")
]
```
is very large in DNF. However, when computing OpamFormula.packages, the
resulting formula will be reduced on a package-by-package basis. By
pre-processing the formula package-by-package, it's instead possible to
capitalise on this pattern and eliminate unrelated sub-formulae before
converting to DNF.
Member
|
I've rebased it on master and added a factorisation in a separate commit because this code pattern is present elsewhere. I noticed it while looking at this part of the code the other day on a performance debugging stroll. Now, while the code change looks reasonable, it isn't exactly trivial either and i'd like to have some tests to see what exactly blows up and if there are some performance regression when giving other types of formulas if any. |
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.
I had a
dependsfield enforcing an invariant for an little-known experimental branch of OCaml:opam switch create oxcaml ocaml-variants.5.2.0+oxcompletely falls over with this. The problem is the conversion to DNF which takes place inOpamFormula.packages.While it's possible to re-encode this formula across more packages (which is the workaround I'm using), the conversion to DNF followed by filtering is sub-optimal.
The observation here is that in
(X1 | X2) & (Y1 | Y2), there's no need to considerY1 | Y2if the atoms ofY1 | Y2are distinct from the atoms ofX1 | X2combined (hopefully correctly) with the observation that if the entire sub-formulaY1 | Y2doesn't refer to the specific package being filtered, then we don't need consider it when converting to DNF.In example above, that means, say, that when considering which versions of the
ocamlpackage to consider, all the disjunctions are eliminated, because the conversion to DNF cannot introduce formula of interest.