perf(gazelle): look for a missing gazelle_python.yaml only once (#4481)

Since manifests are loaded lazily (#2746), `FindThirdPartyDependency`
tries to load the manifest of the importing package and of each parent
package every time it resolves a module name. A manifest that exists is
loaded once and kept, but a missing one is looked for again on every
call. In a repository where only the root has a manifest, that is an
`os.Stat` per parent directory for every candidate module name of every
import.

To fix, the config now remembers that its manifest doesn't exist, and
later calls skip it. `SetGazelleManifestPath` clears the flag, so a new
path is still looked up.

The generated BUILD files are unchanged.

I wrote this change with an AI coding assistant (Claude Code) and
reviewed it myself. I'll read and answer review comments personally; no
agent posts on this PR.
diff --git a/gazelle/pythonconfig/pythonconfig.go b/gazelle/pythonconfig/pythonconfig.go
index e9843aa..9e92d8c 100644
--- a/gazelle/pythonconfig/pythonconfig.go
+++ b/gazelle/pythonconfig/pythonconfig.go
@@ -199,6 +199,7 @@
 	pythonProjectRoot   string
 	gazelleManifestPath string
 	gazelleManifest     *manifest.Manifest
+	noGazelleManifest   bool // gazelleManifestPath doesn't exist
 
 	excludedPatterns                          *singlylinkedlist.List
 	ignoreFiles                               map[string]struct{}
@@ -351,6 +352,7 @@
 // for the current configuration.
 func (c *Config) SetGazelleManifestPath(gazelleManifestPath string) {
 	c.gazelleManifestPath = gazelleManifestPath
+	c.noGazelleManifest = false
 }
 
 // FindThirdPartyDependency scans the gazelle manifests for the current config
@@ -359,12 +361,13 @@
 func (c *Config) FindThirdPartyDependency(modName string) (string, string, bool) {
 	for currentCfg := c; currentCfg != nil; currentCfg = currentCfg.parent {
 		// Attempt to load the manifest if needed.
-		if currentCfg.gazelleManifestPath != "" && currentCfg.gazelleManifest == nil {
+		if currentCfg.gazelleManifestPath != "" && currentCfg.gazelleManifest == nil && !currentCfg.noGazelleManifest {
 			currentCfgManifest, err := loadGazelleManifest(currentCfg.gazelleManifestPath)
 			if err != nil {
 				log.Fatal(err)
 			}
 			currentCfg.SetGazelleManifest(currentCfgManifest)
+			currentCfg.noGazelleManifest = currentCfgManifest == nil // don't look again for every import
 		}
 
 		if currentCfg.gazelleManifest != nil {
diff --git a/news/gazelle-missing-manifest.changed.md b/news/gazelle-missing-manifest.changed.md
new file mode 100644
index 0000000..f0984f1
--- /dev/null
+++ b/news/gazelle-missing-manifest.changed.md
@@ -0,0 +1 @@
+(gazelle) A missing `gazelle_python.yaml` is now looked for only once per directory instead of on every import, which speeds up Gazelle in repositories with many packages.