Skip to content

Commit

Permalink
Put limits on local and inline counts for inlining
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jnthn authored and samcv committed Jul 22, 2019
1 parent 2501678 commit 536cff8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/spesh/inline.c
Expand Up @@ -83,6 +83,16 @@ static int is_static_frame_inlineable(MVMThreadContext *tc, MVMSpeshGraph *inlin
return 0;
}

/* Ensure that we haven't hit size limits. */
if (inliner->num_locals > MVM_SPESH_INLINE_MAX_LOCALS) {
*no_inline_reason = "inliner has too many locals";
return 0;
}
if (inliner->num_inlines > MVM_SPESH_INLINE_MAX_INLINES) {
*no_inline_reason = "inliner has too many inlines";
return 0;
}

return 1;
}

Expand Down
6 changes: 6 additions & 0 deletions src/spesh/inline.h
@@ -1,6 +1,12 @@
/* Default maximum size of bytecode we'll inline. */
#define MVM_SPESH_DEFAULT_MAX_INLINE_SIZE 192

/* The maximum number of locals an inliner can reach, and maximum number of
* inlines we can reach, before we stop inlining; this is to prevent us
* reaching sizes where the analysis becomes hugely costly. */
#define MVM_SPESH_INLINE_MAX_LOCALS 512
#define MVM_SPESH_INLINE_MAX_INLINES 128

/* Inline table entry. The data is primarily used in deopt. */
struct MVMSpeshInline {
/* Start and end position in the bytecode where we're inside of this
Expand Down

0 comments on commit 536cff8

Please sign in to comment.