summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/siggen.py
diff options
context:
space:
mode:
authorEtienne Cordonnier <ecordonnier@snap.com>2023-02-01 15:19:00 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-02-04 17:03:15 +0000
commitedb60ef6fd49764174d140ccae04fca65db131e0 (patch)
tree3945abb66359a2f0a35ada60f1d04aa5c1ff1106 /bitbake/lib/bb/siggen.py
parentde41e1737b6014f651ad8beb08519b3ccbcc34d1 (diff)
downloadpoky-edb60ef6fd49764174d140ccae04fca65db131e0.tar.gz
bitbake: siggen: Fix inefficient string concatenation
As discussed in https://stackoverflow.com/a/4435752/1710392 , CPython has an optimization for statements in the form "a = a + b" or "a += b". It seems that this line does not get optimized, because it has a form a = a + b + c: data = data + "./" + f.split("/./")[1] For that reason, it does a copy of data for each iteration, potentially copying megabytes of data for each iteration. Changing this line causes SignatureGeneratorBasic::get_taskhash to take 0.06 seconds instead of 45 seconds on my test setup where SRC_URI points to a big directory. Note that PEP8 recommends explicitely not to use this optimization which is specific to CPython: "do not rely on CPython’s efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b" However, the PEP8 recommended form using "join()" also does not avoid the copy and takes 45 seconds in my test setup: data = ''.join((data, "./", f.split("/./")[1])) I have changed the other lines to also use += for consistency only, however those were in the form a = a + b and were optimized already. Co-authored-by: JJ Robertson <jrobertson@snap.com> (Bitbake rev: 195750f2ca355e29d51219c58ecb2c1d83692717) Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/siggen.py')
-rw-r--r--bitbake/lib/bb/siggen.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py
index 0e79404f76..26e0243b00 100644
--- a/bitbake/lib/bb/siggen.py
+++ b/bitbake/lib/bb/siggen.py
@@ -349,19 +349,19 @@ class SignatureGeneratorBasic(SignatureGenerator):
349 349
350 data = self.basehash[tid] 350 data = self.basehash[tid]
351 for dep in self.runtaskdeps[tid]: 351 for dep in self.runtaskdeps[tid]:
352 data = data + self.get_unihash(dep) 352 data += self.get_unihash(dep)
353 353
354 for (f, cs) in self.file_checksum_values[tid]: 354 for (f, cs) in self.file_checksum_values[tid]:
355 if cs: 355 if cs:
356 if "/./" in f: 356 if "/./" in f:
357 data = data + "./" + f.split("/./")[1] 357 data += "./" + f.split("/./")[1]
358 data = data + cs 358 data += cs
359 359
360 if tid in self.taints: 360 if tid in self.taints:
361 if self.taints[tid].startswith("nostamp:"): 361 if self.taints[tid].startswith("nostamp:"):
362 data = data + self.taints[tid][8:] 362 data += self.taints[tid][8:]
363 else: 363 else:
364 data = data + self.taints[tid] 364 data += self.taints[tid]
365 365
366 h = hashlib.sha256(data.encode("utf-8")).hexdigest() 366 h = hashlib.sha256(data.encode("utf-8")).hexdigest()
367 self.taskhash[tid] = h 367 self.taskhash[tid] = h