Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intervals::compactConstraint method to optimize constraints #100

Merged
merged 23 commits into from
May 26, 2020

Conversation

Seldaek
Copy link
Member

@Seldaek Seldaek commented May 8, 2020

Could be handy for @Toflar's PR to avoid generating giant constraints when concatenating many MultiConstraints. Remains to be seen whether there is really enough CPU-time benefit though..

src/Intervals.php Show resolved Hide resolved
tests/IntervalsTest.php Outdated Show resolved Hide resolved
src/Intervals.php Outdated Show resolved Hide resolved
src/Intervals.php Outdated Show resolved Hide resolved
@Seldaek
Copy link
Member Author

Seldaek commented May 20, 2020

Need to add more tests for compacting still (help welcome..) and also tests for AnyDevConstraint's compile method and matches to ensure it is not causing issues.

… over optimizing !=x to produce correct constraints
@Seldaek Seldaek force-pushed the compact branch 2 times, most recently from d200742 to a52d7c8 Compare May 21, 2020 12:07
@Seldaek
Copy link
Member Author

Seldaek commented May 21, 2020

Ok more tests added, it now verifies for all Constraint/MultiConstraint::matches tests that after compactConstraint things still match the same way. @naderman please take another look.

…equality with matches on original constraints
src/Intervals.php Outdated Show resolved Hide resolved
src/Intervals.php Outdated Show resolved Hide resolved
src/Intervals.php Outdated Show resolved Hide resolved
@naderman
Copy link
Member

Resulting multiconstraint flag for conjunctive/disjunctive now entirely depends on whether it uses != or == in the numeric part. So what about the constraint != dev-foo && != dev-bar - don't dev branches need some distinction too whether they are disjunctive or conjunctive?

@Seldaek
Copy link
Member Author

Seldaek commented May 22, 2020

Right, fixed a bunch more things in the branch handling area and many new tests. 👍

@naderman naderman merged commit 71d5f9e into composer:master May 26, 2020
Copy link
Contributor

@jderusse jderusse left a comment

Choose a reason for hiding this comment

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

If the Interval is on critical path, way can improve performances by avoiing calling too often the sames methods

// they are zero/+inf
if ($interval->getEnd()->getOperator() === '<' && $i+1 < $count) {
$nextInterval = $intervals['numeric'][$i+1];
if ($interval->getEnd()->getVersion() === $nextInterval->getStart()->getVersion() && $nextInterval->getStart()->getOperator() === '>') {
Copy link
Contributor

Choose a reason for hiding this comment

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

$interval->getEnd() and getStart are called several times in this "else" branch. For better performances, we could store it in a variable

// but this needs to happen as a conjunctive expression together with the start of the current interval
// and end of next interval, so [>=M, <N] || [>N, <P] => [>=M, !=N, <P] but M/P can be skipped if
// they are zero/+inf
if ($interval->getEnd()->getOperator() === '<' && $i+1 < $count) {
Copy link
Contributor

Choose a reason for hiding this comment

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

inverse the 2 test $i+1 < $count is costless than $interval->getEnd()->getOperator()

@Seldaek
Copy link
Member Author

Seldaek commented May 26, 2020

Yeah not sure if those are worth it.. feel free to explore later if you like once we determine whether this is used at all and where. I'd say not really worth obsessing over optimizing away a couple getter fn calls at this point.

One day we'll have readonly props and this can all be public without getters 🙄

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.

None yet

4 participants