From 6a72dd77f4f675ef7a162f0111e092faafc73ff3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Sun, 30 Dec 2018 19:03:02 +0100 Subject: [PATCH] cmd/go: delay parsing the testmain template MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The template is over a hundred lines and full of pipelines, and text/template isn't optimised to parse quickly, so it's no wonder that delaying the parsing to the first template use makes 'go env' much faster. Like in the previous patches to get rid of global regexp.MustCompile vars, use the newly introduced lazytemplate package. Close to two full milliseconds are shaved off of 'go env' runs. name old time/op new time/op delta ExecGoEnv-8 4.27ms ± 0% 2.63ms ± 1% -38.43% (p=0.002 n=6+6) Updates #29382. Change-Id: I4e2569e51ddf2afe1b46eb1a9e9e5845f7a3b0bd Reviewed-on: https://go-review.googlesource.com/c/155962 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/load/test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go index bd6f00bb66..0a9548e5c8 100644 --- a/src/cmd/go/internal/load/test.go +++ b/src/cmd/go/internal/load/test.go @@ -15,10 +15,10 @@ import ( "go/doc" "go/parser" "go/token" + "internal/lazytemplate" "path/filepath" "sort" "strings" - "text/template" "unicode" "unicode/utf8" ) @@ -556,7 +556,7 @@ func checkTestFunc(fn *ast.FuncDecl, arg string) error { return nil } -var testmainTmpl = template.Must(template.New("main").Parse(` +var testmainTmpl = lazytemplate.New("main", ` package main import ( @@ -657,4 +657,4 @@ func main() { {{end}} } -`)) +`) -- 2.51.0