diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-11-02 09:02:15 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-11-03 10:09:59 +0000 |
commit | d654139a833127b16274dca0ccbbab7e3bb33ed0 (patch) | |
tree | 14cd46757ab9ded015516c9078fe9c341d9b9c68 /lib/bb/data.py | |
parent | dfad69d4d8c894a5e1e2686023e41552de09bf3b (diff) | |
download | bitbake-d654139a833127b16274dca0ccbbab7e3bb33ed0.tar.gz |
lib/bb: Fix string concatination potential performance issues
Python scales badly when concatinating strings in loops. Most of these
references aren't problematic but at least one (in data.py) is probably
a performance issue as the issue is compounded as strings become large.
The way to handle this in python is to create lists which don't reconstruct
all the objects when appending to them. We may as well fix all the references
since it stops them being copy/pasted into something problematic in the future.
This patch was based on issues highligthted by a report from AWS Codeguru.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/data.py')
-rw-r--r-- | lib/bb/data.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/bb/data.py b/lib/bb/data.py index 9d18b1e2b..ee5557abf 100644 --- a/lib/bb/data.py +++ b/lib/bb/data.py @@ -285,21 +285,19 @@ def build_dependencies(key, keys, shelldeps, varflagsexcl, d): vardeps = varflags.get("vardeps") def handle_contains(value, contains, d): - newvalue = "" + newvalue = [] + if value: + newvalue.append(str(value)) for k in sorted(contains): l = (d.getVar(k) or "").split() for item in sorted(contains[k]): for word in item.split(): if not word in l: - newvalue += "\n%s{%s} = Unset" % (k, item) + newvalue.append("\n%s{%s} = Unset" % (k, item)) break else: - newvalue += "\n%s{%s} = Set" % (k, item) - if not newvalue: - return value - if not value: - return newvalue - return value + newvalue + newvalue.append("\n%s{%s} = Set" % (k, item)) + return "".join(newvalue) def handle_remove(value, deps, removes, d): for r in sorted(removes): @@ -406,7 +404,9 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): if data is None: bb.error("Task %s from %s seems to be empty?!" % (task, fn)) - data = '' + data = [] + else: + data = [data] gendeps[task] -= whitelist newdeps = gendeps[task] @@ -424,12 +424,12 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): alldeps = sorted(seen) for dep in alldeps: - data = data + dep + data.append(dep) var = lookupcache[dep] if var is not None: - data = data + str(var) + data.append(str(var)) k = fn + ":" + task - basehash[k] = hashlib.sha256(data.encode("utf-8")).hexdigest() + basehash[k] = hashlib.sha256("".join(data).encode("utf-8")).hexdigest() taskdeps[task] = alldeps return taskdeps, basehash |