Skip to content

Commit d339eab

Browse files
committed
Don't apply the -Osize heuristic when inlining coroutines.
This is a performance hack: inlining a coroutine can promote heap allocations of the frame to stack allocations, which is valuable out of proportion to the normal weight. There are surely more principled ways of getting this effect, though.
1 parent 87e9fb5 commit d339eab

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ bool SILPerformanceInliner::isProfitableToInline(
261261
int BaseBenefit = RemovedCallBenefit;
262262

263263
// Osize heuristic.
264+
//
265+
// As a hack, don't apply this at all to coroutine inlining; avoiding
266+
// coroutine allocation overheads is extremely valuable. There might be
267+
// more principled ways of getting this effect.
264268
bool isClassMethodAtOsize = false;
265-
if (OptMode == OptimizationMode::ForSize) {
269+
if (OptMode == OptimizationMode::ForSize && !isa<BeginApplyInst>(AI)) {
266270
// Don't inline into thunks.
267271
if (AI.getFunction()->isThunk())
268272
return false;

0 commit comments

Comments
 (0)