Skip to content

Commit 536cff8

Browse files
jnthnsamcv
authored andcommitted
Put limits on local and inline counts for inlining
We have some non-linear algorithms as part of inlining - of note, in the deopt tracking. If the frame gets too big in various ways, the cost of that can become very large. Put some limits in place to catch such cases, so we won't end up spending a vast amount of time trying to win performance, but end up blocking the application for multiple seconds due to the spesh thread getting stuck in a highly costly loop.
1 parent 2501678 commit 536cff8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/spesh/inline.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ static int is_static_frame_inlineable(MVMThreadContext *tc, MVMSpeshGraph *inlin
8383
return 0;
8484
}
8585

86+
/* Ensure that we haven't hit size limits. */
87+
if (inliner->num_locals > MVM_SPESH_INLINE_MAX_LOCALS) {
88+
*no_inline_reason = "inliner has too many locals";
89+
return 0;
90+
}
91+
if (inliner->num_inlines > MVM_SPESH_INLINE_MAX_INLINES) {
92+
*no_inline_reason = "inliner has too many inlines";
93+
return 0;
94+
}
95+
8696
return 1;
8797
}
8898

src/spesh/inline.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* Default maximum size of bytecode we'll inline. */
22
#define MVM_SPESH_DEFAULT_MAX_INLINE_SIZE 192
33

4+
/* The maximum number of locals an inliner can reach, and maximum number of
5+
* inlines we can reach, before we stop inlining; this is to prevent us
6+
* reaching sizes where the analysis becomes hugely costly. */
7+
#define MVM_SPESH_INLINE_MAX_LOCALS 512
8+
#define MVM_SPESH_INLINE_MAX_INLINES 128
9+
410
/* Inline table entry. The data is primarily used in deopt. */
511
struct MVMSpeshInline {
612
/* Start and end position in the bytecode where we're inside of this

0 commit comments

Comments
 (0)