Skip to contentSkip to conversation

Parsing speed/efficiency, native class extensions and the expand cache

DISCUSSION Richard Purdie 1 participant 1 message Jun 4, 2025

lore
Share & tools
lore
#0 lore raw

I had a look at our parsing for various reasons, partly to see what kind of impact moving deferred inherits would have.

While in there, I noticed the variable expansion cache isn't working as well as it should, particularly for native recipes.

The cache is there to cache the results of variable lookups/expansions. It works by caching results and being cleared any time we write to the datastore.

meta/lib/oe/classextend.py has this code:

def get_depends(varprefix, d):
extcls = d.getVar("EXTENDERCLASS")
return extcls.map_depends_variable(varprefix + "_NONML")

def map_depends_variable(self, varname, suffix = ""):
# We need to preserve EXTENDPKGV so it can be expanded correctly later if suffix:
varname = varname + ":" + suffix
orig = self.d.getVar("EXTENDPKGV", False) self.d.setVar("EXTENDPKGV", "EXTENDPKGV")
deps = self.d.getVar(varname)
if not deps:
self.d.setVar("EXTENDPKGV", orig)
return
deps = bb.utils.explode_dep_versions2(deps)
newdeps = collections.OrderedDict()
for dep in deps:
newdeps[self.map_depends(dep)] = deps[dep]

if not varname.endswith("_NONML"):
self.d.renameVar(varname, varname + "_NONML") self.d.setVar(varname, "${@oe.classextend.get_depends('%s', d)}" % varname) self.d.appendVarFlag(varname, "vardeps", " " + varname + "_NONML")
ret = bb.utils.join_deps(newdeps, False).replace("EXTENDPKGV", "${EXTENDPKGV}") self.d.setVar("EXTENDPKGV", orig)
return ret

i.e. any time we try and expand a RDEPENDS* or similar variable, it has an indirection to oe.classextend.get_depends() and EXTENDPKGV gets set and unset which destroys the expand cache.

Obviously we're doing this for good reason to preserve EXTENDEDPKGV but from a performance perspective it is horrible.

Going back in time, Joshua and I discussed the idea of a [filter] function being applied to variables to try and avoid this kind of problem. Given how horrible the above is, I think it may be time to look at that again...

Cheers,

Richard