From 05d9b4ed26f20a5c2fef66e2a5cb772542e072fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 7 Jan 2023 23:33:03 +0000 Subject: [PATCH] avoid call to loadSharedCache for toolexec calls we skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were doing too much work for tools we don't need to wrap at all, such as `go tool pack` or `go tool buildid`, which get run about as often as the compiler does. The overhead is small per call, but it adds up. name old time/op new time/op delta Build-16 20.7s ± 0% 20.5s ± 1% ~ (p=0.057 n=4+4) name old bin-B new bin-B delta Build-16 5.67M ± 0% 5.66M ± 0% -0.07% (p=0.029 n=4+4) name old cached-time/op new cached-time/op delta Build-16 707ms ± 0% 705ms ± 2% ~ (p=0.886 n=4+4) name old mallocs/op new mallocs/op delta Build-16 25.0M ± 0% 24.9M ± 0% -0.26% (p=0.029 n=4+4) name old sys-time/op new sys-time/op delta Build-16 8.32s ± 2% 7.90s ± 3% -5.05% (p=0.029 n=4+4) --- main.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 3c53eb5..0d868af 100644 --- a/main.go +++ b/main.go @@ -403,31 +403,32 @@ func mainErr(args []string) error { return cmd.Run() case "toolexec": - // We're in a toolexec sub-process, not directly called by the user. - // Load the shared data and wrap the tool, like the compiler or linker. - if err := loadSharedCache(); err != nil { - return err - } - _, tool := filepath.Split(args[0]) if runtime.GOOS == "windows" { tool = strings.TrimSuffix(tool, ".exe") } - if len(args) == 2 && args[1] == "-V=full" { - return alterToolVersion(tool, args) - } - - toolexecImportPath := os.Getenv("TOOLEXEC_IMPORTPATH") - curPkg = cache.ListedPackages[toolexecImportPath] - if curPkg == nil { - return fmt.Errorf("TOOLEXEC_IMPORTPATH not found in listed packages: %s", toolexecImportPath) - } - transform := transformFuncs[tool] transformed := args[1:] if transform != nil { startTime := time.Now() log.Printf("transforming %s with args: %s", tool, strings.Join(transformed, " ")) + + // We're in a toolexec sub-process, not directly called by the user. + // Load the shared data and wrap the tool, like the compiler or linker. + if err := loadSharedCache(); err != nil { + return err + } + + if len(args) == 2 && args[1] == "-V=full" { + return alterToolVersion(tool, args) + } + + toolexecImportPath := os.Getenv("TOOLEXEC_IMPORTPATH") + curPkg = cache.ListedPackages[toolexecImportPath] + if curPkg == nil { + return fmt.Errorf("TOOLEXEC_IMPORTPATH not found in listed packages: %s", toolexecImportPath) + } + var err error if transformed, err = transform(transformed); err != nil { return err