diff mbox series

fetch: Avoid truth-testing the original environment

Message ID 20260923170936.1362930-1-ecordonnier@snap.com
State New
Headers show
Series fetch: Avoid truth-testing the original environment | expand

Commit Message

Etienne Cordonnier Sept. 23, 2026, 5:09 p.m. UTC
From: Etienne Cordonnier <ecordonnier@snap.com>

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)
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 lib/bb/fetch/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
index 55ab710f3..fb6278439 100644
--- a/lib/bb/fetch/__init__.py
+++ b/lib/bb/fetch/__init__.py
@@ -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