From c3094123a112dc4997abc8f02512778af1b4b35c Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 3 Feb 2020 13:29:23 +0300 Subject: [PATCH] compiler: do not store constants as variables Because the constants are loaded directly via `emitLoadConst`, there is no need to store them in an array of locals. It can have a big overhead, because it is done at the beginning of every function. --- pkg/compiler/codegen.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 3ab378404..f6a02fd0f 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -138,7 +138,11 @@ func (c *codegen) convertGlobals(f ast.Node) { case *ast.FuncDecl: return false case *ast.GenDecl: - ast.Walk(c, n) + // constants are loaded directly so there is no need + // to store them as a local variables + if n.Tok != token.CONST { + ast.Walk(c, n) + } } return true })