From 83dcfd62053a80024b1cb282fddf399a36c9c58e Mon Sep 17 00:00:00 2001 From: Lee Cannon Date: Sun, 31 Oct 2021 15:06:55 +0000 Subject: [PATCH] optimize AstGen.callExpr --- src/AstGen.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 509880ec95..b7ab74ed4a 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -7975,8 +7975,14 @@ fn callExpr( const callee = try calleeExpr(gz, scope, call.ast.fn_expr); - const args = try astgen.gpa.alloc(Zir.Inst.Ref, call.ast.params.len); - defer astgen.gpa.free(args); + // A large proportion of calls have 5 or less arguments, due to this preventing allocations + // for calls with few arguments has a sizeable effect on the aggregated runtime of this function + var arg_buffer: [5]Zir.Inst.Ref = undefined; + const args: []Zir.Inst.Ref = if (call.ast.params.len <= arg_buffer.len) + arg_buffer[0..call.ast.params.len] + else + try astgen.gpa.alloc(Zir.Inst.Ref, call.ast.params.len); + defer if (call.ast.params.len > arg_buffer.len) astgen.gpa.free(args); for (call.ast.params) |param_node, i| { // Parameters are always temporary values, they have no