@@ -419,11 +419,12 @@ interp_create_var_explicit (TransformData *td, MonoType *type, int size)
419
419
if (td -> vars_size == td -> vars_capacity ) {
420
420
td -> vars_capacity *= 2 ;
421
421
if (td -> vars_capacity == 0 )
422
- td -> vars_capacity = 2 ;
422
+ td -> vars_capacity = 16 ;
423
423
td -> vars = (InterpVar * ) g_realloc (td -> vars , td -> vars_capacity * sizeof (InterpVar ));
424
424
}
425
425
int mt = mono_mint_type (type );
426
426
InterpVar * local = & td -> vars [td -> vars_size ];
427
+ // FIXME: We don't need to do this memset unless we realloc'd, since we malloc0 vars initially
427
428
memset (local , 0 , sizeof (InterpVar ));
428
429
429
430
local -> type = type ;
@@ -4342,15 +4343,18 @@ interp_method_compute_offsets (TransformData *td, InterpMethod *imethod, MonoMet
4342
4343
int num_args = sig -> hasthis + sig -> param_count ;
4343
4344
int num_il_locals = header -> num_locals ;
4344
4345
int num_locals = num_args + num_il_locals ;
4346
+ // HACK: Pre-reserve extra space to reduce the number of times we realloc during codegen, since it's expensive
4347
+ // 64 vars * 72 bytes = 4608 bytes. Many methods need less than this
4348
+ int target_vars_capacity = num_locals + 64 ;
4345
4349
4346
4350
imethod -> local_offsets = (guint32 * )g_malloc (num_il_locals * sizeof (guint32 ));
4347
- td -> vars = (InterpVar * )g_malloc0 (num_locals * sizeof (InterpVar ));
4351
+ td -> vars = (InterpVar * )g_malloc0 (target_vars_capacity * sizeof (InterpVar ));
4348
4352
td -> vars_size = num_locals ;
4349
- td -> vars_capacity = td -> vars_size ;
4353
+ td -> vars_capacity = target_vars_capacity ;
4350
4354
4351
- td -> renamable_vars = (InterpRenamableVar * )g_malloc (num_locals * sizeof (InterpRenamableVar ));
4355
+ td -> renamable_vars = (InterpRenamableVar * )g_malloc (target_vars_capacity * sizeof (InterpRenamableVar ));
4352
4356
td -> renamable_vars_size = 0 ;
4353
- td -> renamable_vars_capacity = num_locals ;
4357
+ td -> renamable_vars_capacity = target_vars_capacity ;
4354
4358
offset = 0 ;
4355
4359
4356
4360
/*
0 commit comments