-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Use CompilingMatcher in DefaultPolicy for performance reasons #11638
Conversation
The problem is we do treat branches differently here for ordering purposes than for normal constraint matches, hence you have matchSpecific with the second So IMO the only correct way is to keep doing this for branches and skip it otherwise. I don't know if this negates the perf gains but I would imagine it still helps a bit? Can you check? |
It sure does. Here's how you can easily compare: main@755de04bf
This PR@6d3db22
I think that's an easy win for everybody 😊 |
$constraint = new Constraint($operator, $b->getVersion()); | ||
$version = new Constraint('==', $a->getVersion()); | ||
// dev versions need to be compared as branches via matchSpecific's special treatment, the rest can be optimized with compiling matcher | ||
if (strpos($a->getVersion(), 'dev-') === 0 || strpos($b->getVersion(), 'dev-') === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need to worry about versions which end with -dev
?
https://getcomposer.org/doc/articles/versions.md#branches
In the case of a branch with a version-like name (
v1
, in this case), you append-dev
as a suffix, rather than usingdev-
as a prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because those get normalized like e.g v1 branch becomes 1.9999999.9999999.9999999-dev and that plays well with version compare. The problem is really named branches which aren't versions at all.
Alright then let's get this in, thanks! |
@Toflar thanks! 🥳 |
This needs more investigation for sure but I wanted to leave it here so others can investigate too.
I noticed that in the
DefaultPolicy
we do not use theCompilingMatcher
which causes all constraints to be dynamically evaluated over and over again. Since the introduction of thePoolOptimizer
, theDefaultPolicy
is heavily used to select the correct packages within the dependency groups.I did a few tests and this reduces the
PoolOptimizer
runtime by about 10%. The more packages in the pool, the higher the potential savings. In absolute times we're talking 0.2 - 0.5 seconds, maybe.However, in order to make the tests pass, I had to add some
dev-
comparison which I'm a bit confused with. Things to clarify:Constraint::matchSpecific()
and why is this apublic
method and not an implementation detail?CompilingMatcher
handle this case differently - is this a bug incomposer/semver
?