Skip to content

Conversation

@slavapestov
Copy link
Contributor

The PotentialBindings::Constraints set can contain a lot of irrelevant constraints. Removing the iteration over this set from BindingSet::BindingSet speeds type checking a large array literal of tuples of integers by ~25%.

@slavapestov slavapestov force-pushed the binding-set-constructor-speedup branch from 6d3c6f2 to f690933 Compare December 13, 2025 20:05
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

llvm::SmallVector<LiteralRequirement, 2> Literals;

llvm::SmallDenseMap<CanType, Constraint *, 2> Defaults;
llvm::SmallVector<Constraint *, 2> Defaults;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this not make things slower when there duplicate defaultable constraints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, do you mean the same constraint getting added multiple times, or multiple constraints with the same second type? I'll check for both and see if it can happen

Copy link
Contributor

Choose a reason for hiding this comment

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

It could be both I think, this is the worst case when multiple type variables form an equivalence class and each has a literal requirement.

auto &ctx = CS.getASTContext();
return Literals.count(
ctx.getProtocol(KnownProtocolKind::ExpressibleByNilLiteral));
for (const auto &literal : Literals) {
Copy link
Contributor

@xedin xedin Dec 13, 2025

Choose a reason for hiding this comment

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

I guess this could also be slimmed down by llvm::any_of

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

The only place where we did a lookup, we also iterated over it anyway,
and all remaining usages are simplified by downgrading it to a vector.
We shouldn't store a pointer to the ConstraintSystem inside every
BindingSet, but there are some annoying things to untangle before
we can do that.

As a starting point toward that, remove the getConstraintSystem()
getter so that at least we can't reach up to the ConstraintSystem
from the outside.
@slavapestov slavapestov force-pushed the binding-set-constructor-speedup branch from f690933 to d795c18 Compare December 14, 2025 02:17
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

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.

2 participants