Skip to content

Commit

Permalink
Use the FSA instead of malloc in MVM_jit_expr_tree_build
Browse files Browse the repository at this point in the history
The Fixed Size Allocator should be slightly faster than malloc for the
small allocations we need, and possibly much faster than free, because we
know the size of the memory we are deallocating.
  • Loading branch information
nwc10 committed Sep 17, 2021
1 parent fef6205 commit 088bc9c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/jit/expr.c
Expand Up @@ -707,13 +707,15 @@ MVMJitExprTree * MVM_jit_expr_tree_build(MVMThreadContext *tc, MVMJitGraph *jg,
MVMuint16 operands_needed = MAX(2, ins->info->num_operands); /* At least 2 for inc_i hack */
if (operands_needed > operands_allocated) {
/* Round up to an even number - we're allocating an array of 4 byte
integers, so assume malloc will align (at least) to 8 bytes, and
hence avoid some "churn" */
integers, whilst the FSA will align (at least) to 8 bytes. Hence
avoid some "churn" */
if (operands_needed & 1) {
++operands_needed;
}
MVM_free(operands);
operands = MVM_malloc(operands_needed * sizeof(MVMint32));
if (operands) {
MVM_fixed_size_free(tc, tc->instance->fsa, operands_allocated * sizeof(MVMint32), operands);
}
operands = MVM_fixed_size_alloc(tc, tc->instance->fsa, operands_needed * sizeof(MVMint32));
operands_allocated = operands_needed;
}
MVMSpeshAnn *ann;
Expand Down Expand Up @@ -914,7 +916,7 @@ MVMJitExprTree * MVM_jit_expr_tree_build(MVMThreadContext *tc, MVMJitGraph *jg,
tree = NULL;
}
MVM_free(values);
MVM_free(operands);
MVM_fixed_size_free(tc, tc->instance->fsa, operands_allocated * sizeof(MVMint32), operands);
return tree;
}

Expand Down

0 comments on commit 088bc9c

Please sign in to comment.