summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorEtienne Cordonnier <ecordonnier@snap.com>2023-09-20 09:41:48 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-09-22 07:45:47 +0100
commit46386988349e9247640841202165a92a9bd1db3c (patch)
tree01848a61db8b1333f6b0b45c30b7d0302e65ee79 /bitbake
parent2a581252eae2c506237fb22f1f39fc26849b6431 (diff)
downloadpoky-46386988349e9247640841202165a92a9bd1db3c.tar.gz
bitbake: bitbake-worker/runqueue: Avoid unnecessary bytes object copies
declaring queue=b"" creates an object of types bytes(). bytes() is an immutable object, and therefore doing "self.queue = self.queue + r" creates a new object containing "self.queue" concatenated with "r". On my test setup, we are passing 180MB of data of "workerdata" to the bitbake-worker, so those copies significantly slow down the initialization of the bitbake-worker. Rather use bytearray() which a mutable type, and use extend() to avoid copies. In my test setup, byterray.extend() is 10.000 times faster than copying the queue, for a queue size of 180MB. (Bitbake rev: 2302b5316091dff189e6c3f546341b2274ed9d0a) Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rwxr-xr-xbitbake/bin/bitbake-worker14
-rw-r--r--bitbake/lib/bb/runqueue.py4
2 files changed, 9 insertions, 9 deletions
diff --git a/bitbake/bin/bitbake-worker b/bitbake/bin/bitbake-worker
index 451e6926bf..609e276fe2 100755
--- a/bitbake/bin/bitbake-worker
+++ b/bitbake/bin/bitbake-worker
@@ -91,19 +91,19 @@ def worker_fire_prepickled(event):
91worker_thread_exit = False 91worker_thread_exit = False
92 92
93def worker_flush(worker_queue): 93def worker_flush(worker_queue):
94 worker_queue_int = b"" 94 worker_queue_int = bytearray()
95 global worker_pipe, worker_thread_exit 95 global worker_pipe, worker_thread_exit
96 96
97 while True: 97 while True:
98 try: 98 try:
99 worker_queue_int = worker_queue_int + worker_queue.get(True, 1) 99 worker_queue_int.extend(worker_queue.get(True, 1))
100 except queue.Empty: 100 except queue.Empty:
101 pass 101 pass
102 while (worker_queue_int or not worker_queue.empty()): 102 while (worker_queue_int or not worker_queue.empty()):
103 try: 103 try:
104 (_, ready, _) = select.select([], [worker_pipe], [], 1) 104 (_, ready, _) = select.select([], [worker_pipe], [], 1)
105 if not worker_queue.empty(): 105 if not worker_queue.empty():
106 worker_queue_int = worker_queue_int + worker_queue.get() 106 worker_queue_int.extend(worker_queue.get())
107 written = os.write(worker_pipe, worker_queue_int) 107 written = os.write(worker_pipe, worker_queue_int)
108 worker_queue_int = worker_queue_int[written:] 108 worker_queue_int = worker_queue_int[written:]
109 except (IOError, OSError) as e: 109 except (IOError, OSError) as e:
@@ -346,12 +346,12 @@ class runQueueWorkerPipe():
346 if pipeout: 346 if pipeout:
347 pipeout.close() 347 pipeout.close()
348 bb.utils.nonblockingfd(self.input) 348 bb.utils.nonblockingfd(self.input)
349 self.queue = b"" 349 self.queue = bytearray()
350 350
351 def read(self): 351 def read(self):
352 start = len(self.queue) 352 start = len(self.queue)
353 try: 353 try:
354 self.queue = self.queue + (self.input.read(102400) or b"") 354 self.queue.extend(self.input.read(102400) or b"")
355 except (OSError, IOError) as e: 355 except (OSError, IOError) as e:
356 if e.errno != errno.EAGAIN: 356 if e.errno != errno.EAGAIN:
357 raise 357 raise
@@ -379,7 +379,7 @@ class BitbakeWorker(object):
379 def __init__(self, din): 379 def __init__(self, din):
380 self.input = din 380 self.input = din
381 bb.utils.nonblockingfd(self.input) 381 bb.utils.nonblockingfd(self.input)
382 self.queue = b"" 382 self.queue = bytearray()
383 self.cookercfg = None 383 self.cookercfg = None
384 self.databuilder = None 384 self.databuilder = None
385 self.data = None 385 self.data = None
@@ -413,7 +413,7 @@ class BitbakeWorker(object):
413 if len(r) == 0: 413 if len(r) == 0:
414 # EOF on pipe, server must have terminated 414 # EOF on pipe, server must have terminated
415 self.sigterm_exception(signal.SIGTERM, None) 415 self.sigterm_exception(signal.SIGTERM, None)
416 self.queue = self.queue + r 416 self.queue.extend(r)
417 except (OSError, IOError): 417 except (OSError, IOError):
418 pass 418 pass
419 if len(self.queue): 419 if len(self.queue):
diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py
index c88d7129ca..c40a3be212 100644
--- a/bitbake/lib/bb/runqueue.py
+++ b/bitbake/lib/bb/runqueue.py
@@ -3159,7 +3159,7 @@ class runQueuePipe():
3159 if pipeout: 3159 if pipeout:
3160 pipeout.close() 3160 pipeout.close()
3161 bb.utils.nonblockingfd(self.input) 3161 bb.utils.nonblockingfd(self.input)
3162 self.queue = b"" 3162 self.queue = bytearray()
3163 self.d = d 3163 self.d = d
3164 self.rq = rq 3164 self.rq = rq
3165 self.rqexec = rqexec 3165 self.rqexec = rqexec
@@ -3178,7 +3178,7 @@ class runQueuePipe():
3178 3178
3179 start = len(self.queue) 3179 start = len(self.queue)
3180 try: 3180 try:
3181 self.queue = self.queue + (self.input.read(102400) or b"") 3181 self.queue.extend(self.input.read(102400) or b"")
3182 except (OSError, IOError) as e: 3182 except (OSError, IOError) as e:
3183 if e.errno != errno.EAGAIN: 3183 if e.errno != errno.EAGAIN:
3184 raise 3184 raise