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:12:42 +0000 |
commit | 34e4eebc32c4836fc40098e90b17c00f51398967 (patch) | |
tree | 20f3ba43c0341cbed8b454c92d60e0fc326b9d50 /bitbake/lib/bb/data.py | |
parent | 791d6e63be09b361dd3397707a0507399b9a9ce7 (diff) | |
download | poky-34e4eebc32c4836fc40098e90b17c00f51398967.tar.gz |
bitbake: 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.
(Bitbake rev: d654139a833127b16274dca0ccbbab7e3bb33ed0)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/data.py')
-rw-r--r-- | bitbake/lib/bb/data.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/bitbake/lib/bb/data.py b/bitbake/lib/bb/data.py index 9d18b1e2bf..ee5557abfa 100644 --- a/bitbake/lib/bb/data.py +++ b/bitbake/lib/bb/data.py | |||
@@ -285,21 +285,19 @@ def build_dependencies(key, keys, shelldeps, varflagsexcl, d): | |||
285 | vardeps = varflags.get("vardeps") | 285 | vardeps = varflags.get("vardeps") |
286 | 286 | ||
287 | def handle_contains(value, contains, d): | 287 | def handle_contains(value, contains, d): |
288 | newvalue = "" | 288 | newvalue = [] |
289 | if value: | ||
290 | newvalue.append(str(value)) | ||
289 | for k in sorted(contains): | 291 | for k in sorted(contains): |
290 | l = (d.getVar(k) or "").split() | 292 | l = (d.getVar(k) or "").split() |
291 | for item in sorted(contains[k]): | 293 | for item in sorted(contains[k]): |
292 | for word in item.split(): | 294 | for word in item.split(): |
293 | if not word in l: | 295 | if not word in l: |
294 | newvalue += "\n%s{%s} = Unset" % (k, item) | 296 | newvalue.append("\n%s{%s} = Unset" % (k, item)) |
295 | break | 297 | break |
296 | else: | 298 | else: |
297 | newvalue += "\n%s{%s} = Set" % (k, item) | 299 | newvalue.append("\n%s{%s} = Set" % (k, item)) |
298 | if not newvalue: | 300 | return "".join(newvalue) |
299 | return value | ||
300 | if not value: | ||
301 | return newvalue | ||
302 | return value + newvalue | ||
303 | 301 | ||
304 | def handle_remove(value, deps, removes, d): | 302 | def handle_remove(value, deps, removes, d): |
305 | for r in sorted(removes): | 303 | for r in sorted(removes): |
@@ -406,7 +404,9 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): | |||
406 | 404 | ||
407 | if data is None: | 405 | if data is None: |
408 | bb.error("Task %s from %s seems to be empty?!" % (task, fn)) | 406 | bb.error("Task %s from %s seems to be empty?!" % (task, fn)) |
409 | data = '' | 407 | data = [] |
408 | else: | ||
409 | data = [data] | ||
410 | 410 | ||
411 | gendeps[task] -= whitelist | 411 | gendeps[task] -= whitelist |
412 | newdeps = gendeps[task] | 412 | newdeps = gendeps[task] |
@@ -424,12 +424,12 @@ def generate_dependency_hash(tasklist, gendeps, lookupcache, whitelist, fn): | |||
424 | 424 | ||
425 | alldeps = sorted(seen) | 425 | alldeps = sorted(seen) |
426 | for dep in alldeps: | 426 | for dep in alldeps: |
427 | data = data + dep | 427 | data.append(dep) |
428 | var = lookupcache[dep] | 428 | var = lookupcache[dep] |
429 | if var is not None: | 429 | if var is not None: |
430 | data = data + str(var) | 430 | data.append(str(var)) |
431 | k = fn + ":" + task | 431 | k = fn + ":" + task |
432 | basehash[k] = hashlib.sha256(data.encode("utf-8")).hexdigest() | 432 | basehash[k] = hashlib.sha256("".join(data).encode("utf-8")).hexdigest() |
433 | taskdeps[task] = alldeps | 433 | taskdeps[task] = alldeps |
434 | 434 | ||
435 | return taskdeps, basehash | 435 | return taskdeps, basehash |