Conversation
GrahamCampbell
left a comment
There was a problem hiding this comment.
Should add a test with ^0.1 || ^1.0 || ^2.0 to test that is NOT collapsed.
You mean |
|
I added new cases to also merge multiple other constraints
# before
Multiple:
Multiple: >= 1.0 <2.0 != 1.0.1
Multiple: >= 2.0 <3.0 != 2.0.1
Multiple: >= 3.0 <4.0
Multiple: >= 4.0 <5.0 != 4.0.1
# after
Multiple: >= 1.0 <5.0 != 1.0.1 != 2.0.1 != 4.0.1 |
|
NOTE: this PR does not try to optimize user's mistake (range overlaps): It would have a cost at runtime for something that should not happens: ie: |
Codecov Report
@@ Coverage Diff @@
## master #84 +/- ##
============================================
- Coverage 96.03% 95.42% -0.61%
- Complexity 250 257 +7
============================================
Files 7 7
Lines 479 503 +24
============================================
+ Hits 460 480 +20
- Misses 19 23 +4
Continue to review full report at Codecov.
|
|
Great to see someone picking up where I left off :)
Unfortunately, that‘s not an option because it‘s also used internally by Composer itself. |
|
I had this on my list anyway but maybe you wanna give it a shot: We might want to use lower and upper constraint bounds for optimizing them :) |
|
I think you misunderstood what's I'm saying. Such case will still works, but it will not be optimized. In short, it will not be better nor worse than the current implementation. |
I thought about that but did not get the expected results... Without cache, optimizing such case reduce overall performances :-( opportunity for a |
Ah, good then :) And yes, compilation would be great, that‘s why there‘s #71 :) |
|
Looks good to me code wise but do you have any numbers on a few composer runs what the impact is? I'm just worried that too intensive optimization leads to higher CPU time for only a minor memory gain.. but hopefully that's not the case. |
|
The gain is not about memory, It's also about CPU: It reduces the number of constraint evaluate Here is a comparison of for magento (-5% cpu): https://blackfire.io/profiles/compare/3897a2dc-7956-40b6-9118-204906544244/graph (reduce from 382,940 to 369,053 calls to And antorher on a personal project: https://blackfire.io/profiles/compare/dc399174-be9e-4bec-9046-21b1f376c448/graph |
|
That looks really cool @jderusse - did you take a look at actually dealing with overlaps in the constraints? This isn't really relevant right now, but @Toflar and I are considering options to optimize building the package pool in Composer and would need to merge constraints for the same package from multiple require statements in other packes, so they are likely to overlap. If there's more of a performance hit for that, we could make it a separate function too, which would only be called in that specific context? |
|
@naderman
That would not be an issue if optimization were cached (which is not the case for the moment). |
|
I don't think you read all of what I wrote? We're talking about a future change in Composer that would result in overlap not being rare anymore at all. Like I said a separate function to apply this optimization only for the use case where overlap is common seems alright to me? |
<3 |
|
Seems like this doesn't do much in terms of CPU/memory change (I see a tiny bit less memory, and CPU probably too but so small it's hard to tell if relevant). That said, if there is an impact on larger projects that's good, and anyway it's a good improvement code wise! Thanks. |
|
And as @naderman said, if you are interested in working on optimization of overlapping constraints as a separate util class, that would probably be valuable to have too :) |
This PR optimize the MultiConstraint by alowing more than 2 constraints:
^1.0 || ^2.0 || ^3.0=>>= 1.0 <4.0It also replace calls to
MultiConstraintmethods by accessing private properties (allowed because same class)