Skip to content

Commit f0c52f5

Browse files
committed
Sema: Cache Solution::getTotalMemory()
This is showing up in performance profiles.
1 parent a19c92a commit f0c52f5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,9 @@ class Solution {
14741474
/// The fixed score for this solution.
14751475
Score FixedScore;
14761476

1477+
/// The total memory used by this solution.
1478+
std::optional<size_t> TotalMemory;
1479+
14771480
public:
14781481
/// Create a solution for the given constraint system.
14791482
Solution(ConstraintSystem &cs, const Score &score)

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,11 @@ static inline size_t size_in_bytes(const T &x) {
18681868
}
18691869

18701870
size_t Solution::getTotalMemory() const {
1871-
return sizeof(*this) + typeBindings.getMemorySize() +
1871+
if (TotalMemory)
1872+
return *TotalMemory;
1873+
1874+
const_cast<Solution *>(this)->TotalMemory
1875+
= sizeof(*this) + typeBindings.getMemorySize() +
18721876
overloadChoices.getMemorySize() +
18731877
ConstraintRestrictions.getMemorySize() +
18741878
(Fixes.size() * sizeof(void *)) + DisjunctionChoices.getMemorySize() +
@@ -1892,6 +1896,8 @@ size_t Solution::getTotalMemory() const {
18921896
size_in_bytes(argumentLists) +
18931897
size_in_bytes(ImplicitCallAsFunctionRoots) +
18941898
size_in_bytes(SynthesizedConformances);
1899+
1900+
return *TotalMemory;
18951901
}
18961902

18971903
DeclContext *Solution::getDC() const { return constraintSystem->DC; }

0 commit comments

Comments
 (0)