Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Reduce number of reallocs inside interp_create_var_explicit #100801

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,12 @@ interp_create_var_explicit (TransformData *td, MonoType *type, int size)
if (td->vars_size == td->vars_capacity) {
td->vars_capacity *= 2;
if (td->vars_capacity == 0)
td->vars_capacity = 2;
td->vars_capacity = 16;
td->vars = (InterpVar*) g_realloc (td->vars, td->vars_capacity * sizeof (InterpVar));
}
int mt = mono_mint_type (type);
InterpVar *local = &td->vars [td->vars_size];
// FIXME: We don't need to do this memset unless we realloc'd, since we malloc0 vars initially
memset (local, 0, sizeof (InterpVar));

local->type = type;
Expand Down Expand Up @@ -4313,15 +4314,18 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet
int num_args = sig->hasthis + sig->param_count;
int num_il_locals = header->num_locals;
int num_locals = num_args + num_il_locals;
// HACK: Pre-reserve extra space to reduce the number of times we realloc during codegen, since it's expensive
// 64 vars * 72 bytes = 4608 bytes. Many methods need less than this
int target_vars_capacity = num_locals + 64;

imethod->local_offsets = (guint32*)g_malloc (num_il_locals * sizeof(guint32));
td->vars = (InterpVar*)g_malloc0 (num_locals * sizeof (InterpVar));
td->vars = (InterpVar*)g_malloc0 (target_vars_capacity * sizeof (InterpVar));
td->vars_size = num_locals;
td->vars_capacity = td->vars_size;
td->vars_capacity = target_vars_capacity;

td->renamable_vars = (InterpRenamableVar*)g_malloc (num_locals * sizeof (InterpRenamableVar));
td->renamable_vars = (InterpRenamableVar*)g_malloc (target_vars_capacity * sizeof (InterpRenamableVar));
td->renamable_vars_size = 0;
td->renamable_vars_capacity = num_locals;
td->renamable_vars_capacity = target_vars_capacity;
offset = 0;

/*
Expand Down
Loading