data_smart: Skip commonly accessed variables from variable data context lookup
PATCH 1/3 data_smart: Skip commonly accessed variables from variable data context lookup
The code tries to expand missing entities when they're encountered in python expressions. Looking at traces, these are often things which would not be in the data store such as "bb".
Optimise to skip the data store queries for things we know will never be there. The expansion cache usually covers these but skipping entirely cuts a few million function calls parsing OE-Core.
--- lib/bb/data_smart.py | 3 +++ 1 file changed, 3 insertions(+)
lib/bb/data_smart.py +3 -0
@@ -152,6 +152,9 @@ class DataContext(dict): self['d'] = metadata def __missing__(self, key): + # Skip commonly accessed invalid variables + if key in ['bb', 'oe', 'int', 'bool', 'time', 'str', 'os']: + raise KeyError(key) value = self.metadata.getVar(key) if value is None or self.metadata.getVarFlag(key, 'func', False): raise KeyError(key)
Signature · 1 line
2.32.0
PATCH 2/3 data_smart: Avoid multiple getVarFlag calls
We can call getVarFlags() instead of the multiple getVarFlag calls which is a little more efficient. This reduces the number of overall function calls so is good but probably isn't much faster (or slower).
--- lib/bb/data_smart.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
lib/bb/data_smart.py +4 -3
@@ -673,10 +673,11 @@ class DataSmart(MutableMapping): self.varhistory.record(**loginfo) self.setVar(newkey, val, ignore=True, parsing=True) - for i in (__setvar_keyword__): - src = self.getVarFlag(key, i, False) - if src is None: + srcflags = self.getVarFlags(key, False, True) or {} + for i in srcflags: + if i not in (__setvar_keyword__): continue + src = srcflags[i] dest = self.getVarFlag(newkey, i, False) or [] dest.extend(src)
Signature · 1 line
2.32.0
PATCH 3/3 codeparser: Avoid log bufer overhead in cache case
In reply to Richard PurdieCreating the new log instances triggers a lot of python logging overhead in a commonly called function (about 600,000 for parsing OE-Core).
We only need the log functionality if we're parsing, not if we just hit from the cache. Therefore defer the log setup overhead until we know it is a cache miss.
Whilst this complicates the code slightly, the performance gain is worth it as for parsing OE-Core we drop 60 million funciton calls (from 225 overall).
--- lib/bb/codeparser.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
lib/bb/codeparser.py +18 -2
@@ -195,6 +195,10 @@ class BufferedLogger(Logger): self.target.handle(record) self.buffer = [] +class DummyLogger(): + def flush(self): + return + class PythonParser(): getvars = (".getVar", ".appendVar", ".prependVar", "oe.utils.conditional") getvarflags = (".getVarFlag", ".appendVarFlag", ".prependVarFlag")
@@ -276,7 +280,9 @@ class PythonParser(): self.contains = {} self.execs = set() self.references = set() - self.log = BufferedLogger('BitBake.Data.PythonParser', logging.DEBUG, log) + self._log = log + # Defer init as expensive + self.log = DummyLogger() self.unhandled_message = "in call of %s, argument '%s' is not a string literal" self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message)
@@ -303,6 +309,9 @@ class PythonParser(): self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i]) return + # Need to parse so take the hit on the real log buffer + self.log = BufferedLogger('BitBake.Data.PythonParser', logging.DEBUG, self._log) + # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though node = "\n" * int(lineno) + node code = compile(check_indent(str(node)), filename, "exec",
@@ -321,7 +330,11 @@ class ShellParser(): self.funcdefs = set() self.allexecs = set() self.execs = set() - self.log = BufferedLogger('BitBake.Data.%s' % name, logging.DEBUG, log) + self._name = name + self._log = log + # Defer init as expensive + self.log = DummyLogger() + self.unhandled_template = "unable to handle non-literal command '%s'" self.unhandled_template = "while parsing %s, %s" % (name, self.unhandled_template)
@@ -340,6 +353,9 @@ class ShellParser(): self.execs = set(codeparsercache.shellcacheextras[h].execs) return self.execs + # Need to parse so take the hit on the real log buffer + self.log = BufferedLogger('BitBake.Data.%s' % self._name, logging.DEBUG, self._log) + self._parse_shell(value) self.execs = set(cmd for cmd in self.allexecs if cmd not in self.funcdefs)
Signature · 1 line
2.32.0