-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Perf Experiment][ConstraintGraph] Gather constraints improvements #18281
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
[Perf Experiment][ConstraintGraph] Gather constraints improvements #18281
Conversation
Since it's possible to find the same constraint through two different but equivalent type variables, let's use a set to store constraints instead of a vector to avoid processing the same constraint multiple times.
Most of the use-cases of `gatherConstraints` require filtering at least based on the constraint kind that caller is interested in, so instead of returning unrelated results and asking caller to filter separately, let's add that functionality directly to `gatherConstraints`.
@swift-ci please smoke test compiler performance |
lib/Sema/CSBindings.cpp
Outdated
@@ -361,8 +361,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) { | |||
assert(!typeVar->getImpl().getFixedType(nullptr) && "has a fixed type"); | |||
|
|||
// Gather the constraints associated with this type variable. | |||
SmallVector<Constraint *, 8> constraints; | |||
llvm::SmallPtrSet<Constraint *, 4> visitedConstraints; | |||
SmallPtrSet<Constraint *, 8> constraints; |
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.
Sets are unordered collections and as a result you have no stable order when iterating over them. This is especially bad with sets of pointers since you're almost certainly guaranteed change in order from run to run.
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.
I can switch it to SmallSetVector
which should have insertion order iteration. Will try that next.
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.
Oh it looks like C++
's std::set
is guaranteed to use std::less
and you're guaranteed an iteration order, but again with pointers as the elements you will not be guaranteed to iterate over the pointed-to elements in the same order from run to run.
For stable iteration order, let's switch from `SmallPtrSet` to `SetVector` which ensures insertion order iteration.
@swift-ci please smoke test compiler performance |
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.
Definitely cleaner!
lib/Sema/CSDiag.cpp
Outdated
tv, constraints, ConstraintGraph::GatheringKind::EquivalenceClass, | ||
[&](Constraint *constraint) -> bool { | ||
// We are not interested in ConformsTo constraints because | ||
// such constraints specify restrictions on the archetypes |
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.
I'd rather not say "archetypes" here; I think the reason we don't care about conformsTo
constraints is that we can't derive any concrete type information from them.
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.
Sounds good! It's an existing comment I've moved here but I'll fix it up if perf test is green...
Build comment file:Summary for master smoketestUnexpected test results, excluded stats for Kingfisher, ReactiveCocoa No regressions above thresholds Debugdebug briefRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (2)
debug detailedRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
Releaserelease briefRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (2)
release detailedRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (23)
|
@swift-ci please smoke test |
@swift-ci please test source compatibility |
Failure in |
gatherConstraints
per type variable