Skip to content

Commit 6a72dd7

Browse files
committed
cmd/go: delay parsing the testmain template
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í <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 61170f8 commit 6a72dd7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cmd/go/internal/load/test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"go/doc"
1616
"go/parser"
1717
"go/token"
18+
"internal/lazytemplate"
1819
"path/filepath"
1920
"sort"
2021
"strings"
21-
"text/template"
2222
"unicode"
2323
"unicode/utf8"
2424
)
@@ -556,7 +556,7 @@ func checkTestFunc(fn *ast.FuncDecl, arg string) error {
556556
return nil
557557
}
558558

559-
var testmainTmpl = template.Must(template.New("main").Parse(`
559+
var testmainTmpl = lazytemplate.New("main", `
560560
package main
561561
562562
import (
@@ -657,4 +657,4 @@ func main() {
657657
{{end}}
658658
}
659659
660-
`))
660+
`)

0 commit comments

Comments
 (0)