From b38f42da0fb333fef941cc4522ca566962bfc4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 24 Nov 2024 14:16:46 +0000 Subject: [PATCH] stop using listedPackage.IgnoredGoFiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We used it to detect GOOS-specific packages and ignore their load errors without having to do a substring search. However, it turns out that repeatedly loading the string slice from gob files in the cache is rather slow, particularly since many Go packages have dozens of GOOS-specific files which can be ignored. │ old │ new │ │ cached-sec/op │ cached-sec/op vs base │ Build-8 340.3m ± 1% 335.8m ± 2% -1.32% (p=0.002 n=10) │ old │ new │ │ mallocs/op │ mallocs/op vs base │ Build-8 35.73M ± 0% 35.09M ± 0% -1.79% (p=0.000 n=10) --- shared.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shared.go b/shared.go index 00bf9da..287d727 100644 --- a/shared.go +++ b/shared.go @@ -151,7 +151,6 @@ type listedPackage struct { Dir string CompiledGoFiles []string - IgnoredGoFiles []string Imports []string Error *packageError // to report package loading errors to the user @@ -300,7 +299,7 @@ func appendListedPackages(packages []string, mainBuild bool) error { } if perr := pkg.Error; perr != nil { - if !mainBuild && len(pkg.CompiledGoFiles) == 0 && len(pkg.IgnoredGoFiles) > 0 { + if !mainBuild && strings.Contains(perr.Err, "build constraints exclude all Go files") { // Some packages in runtimeLinknamed need a build tag to be importable, // like crypto/internal/boring/fipstls with boringcrypto, // so any pkg.Error should be ignored when the build tag isn't set.