Skip to contentSkip to conversation

fetch: Avoid truth-testing the original environment

PATCH New [email protected] 1 participant 1 message Sep 23

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch: Avoid truth-testing the original environment

From: Etienne Cordonnier <[email protected]>

get_fetcher_environment() and runfetchcmd() check BB_ORIGENV with a truth test for every export variable that is not set in the datastore. Truth testing a DataSmart calls __len__(), which builds the set of all its keys, so this repeatedly enumerates the whole original environment. BB_ORIGENV is always a datastore when set, so compare it against None instead.

This reduces get_fetcher_environment(), called once per sstate object checked on an HTTP mirror, from 753us to 24us. Checking 2,114 objects on the Yocto sstate mirror with BB_NUMBER_THREADS = "8" reduced the time to task execution from 26.6s to 24.5s on average.

AI-Generated: Uses Claude Code (Claude Opus 5.5)

---
 lib/bb/fetch/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bb/fetch/__init__.py +2 -2
index 55ab710f3..fb6278439 100644
@@ -928,7 +928,7 @@ def get_fetcher_environment(d):
     origenv = d.getVar("BB_ORIGENV")
     for name in bb.fetch.FETCH_EXPORT_VARS:
         value = d.getVar(name)
-        if not value and origenv:
+        if not value and origenv is not None:
             value = origenv.getVar(name)
         if value:
             newenv[name] = value
@@ -961,7 +961,7 @@ def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None, extra
     origenv = d.getVar("BB_ORIGENV", False)
     env = os.environ.copy()
     for var in exportvars:
-        val = d.getVar(var) or (origenv and origenv.getVar(var))
+        val = d.getVar(var) or (origenv is not None and origenv.getVar(var))
         if val:
             env[var] = val
 
Signature · 1 line
2.43.0