Skip to content

Commit f30ba33

Browse files
authored
Make Tunables::inlining_sum_size_threshold a hard limit (#11458)
* Make `Tunables::inlining_sum_size_threshold` a hard limit This prevents infinitely inlining small recursive functions whose size is less than `Tunables::small_callee_size`. * Add test case
1 parent f8177c2 commit f30ba33

2 files changed

Lines changed: 7354 additions & 12 deletions

File tree

crates/wasmtime/src/compile.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,18 @@ the use case.
853853
"we never inline recursion"
854854
);
855855

856+
// Put a limit on how large we can make a function via inlining to cap
857+
// code bloat.
858+
let sum_size = caller_size.saturating_add(callee_size);
859+
if sum_size > tunables.inlining_sum_size_threshold {
860+
log::trace!(
861+
" --> not inlining: the sum of the caller's and callee's sizes is greater than \
862+
the inlining-sum-size threshold: {callee_size} + {caller_size} > {}",
863+
tunables.inlining_sum_size_threshold
864+
);
865+
return false;
866+
}
867+
856868
// Consider whether this is an intra-module call.
857869
//
858870
// Inlining within a single core module has most often already been done
@@ -890,18 +902,6 @@ the use case.
890902
return true;
891903
}
892904

893-
// It is often not worth inlining if the sum of the caller and callee
894-
// sizes is too large.
895-
let sum_size = caller_size.saturating_add(callee_size);
896-
if sum_size > tunables.inlining_sum_size_threshold {
897-
log::trace!(
898-
" --> not inlining: the sum of the caller's and callee's sizes is greater than \
899-
the inlining-sum-size threshold: {callee_size} + {caller_size} > {}",
900-
tunables.inlining_sum_size_threshold
901-
);
902-
return false;
903-
}
904-
905905
log::trace!(" --> inlining: did not find a reason we should not");
906906
true
907907
}

0 commit comments

Comments
 (0)