go/packages: pass -pgo=off on go1.21 and later

PGO variants can be costly to compute, and can result in unnecessary
packages for the caller. They are also unlikely to be useful.

Disable these variants by default, setting -pgo=off on go1.21 and later.
If someone wants to see PGO variants we can have a NeedPGO flag, but
that should be a separate proposal.

Fixes golang/go#60456

Change-Id: Ifc706fe7503f841cbe4fa4326b08717a70b4368b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498557
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/go/packages/golist.go b/go/packages/golist.go
index 6bb7168..aa2ca3b 100644
--- a/go/packages/golist.go
+++ b/go/packages/golist.go
@@ -891,6 +891,15 @@
 		// probably because you'd just get the TestMain.
 		fmt.Sprintf("-find=%t", !cfg.Tests && cfg.Mode&findFlags == 0 && !usesExportData(cfg)),
 	}
+
+	// golang/go#60456: with go1.21 and later, go list serves pgo variants, which
+	// can be costly to compute and may result in redundant processing for the
+	// caller. Disable these variants. If someone wants to add e.g. a NeedPGO
+	// mode flag, that should be a separate proposal.
+	if goVersion >= 21 {
+		fullargs = append(fullargs, "-pgo=off")
+	}
+
 	fullargs = append(fullargs, cfg.BuildFlags...)
 	fullargs = append(fullargs, "--")
 	fullargs = append(fullargs, words...)