diff options
| author | Etienne Cordonnier <ecordonnier@snap.com> | 2023-09-22 10:51:46 +0200 |
|---|---|---|
| committer | Steve Sakoman <steve@sakoman.com> | 2023-10-18 05:13:24 -1000 |
| commit | 3a3afebf41077e097150bc33f3e292eed929ba11 (patch) | |
| tree | 6e3ce05bef44a71f69398bca954a7959a974c69d /bitbake/lib/bb | |
| parent | 222be3e3b989cb32cd8e3601615fac276c04c3ea (diff) | |
| download | poky-3a3afebf41077e097150bc33f3e292eed929ba11.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: 9993a89e5b97dda5f3657e5a7cc3a4fa94ff7111)
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'bitbake/lib/bb')
| -rw-r--r-- | bitbake/lib/bb/runqueue.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py index 569520707b..46ff30a7d3 100644 --- a/bitbake/lib/bb/runqueue.py +++ b/bitbake/lib/bb/runqueue.py | |||
| @@ -3101,7 +3101,7 @@ class runQueuePipe(): | |||
| 3101 | if pipeout: | 3101 | if pipeout: |
| 3102 | pipeout.close() | 3102 | pipeout.close() |
| 3103 | bb.utils.nonblockingfd(self.input) | 3103 | bb.utils.nonblockingfd(self.input) |
| 3104 | self.queue = b"" | 3104 | self.queue = bytearray() |
| 3105 | self.d = d | 3105 | self.d = d |
| 3106 | self.rq = rq | 3106 | self.rq = rq |
| 3107 | self.rqexec = rqexec | 3107 | self.rqexec = rqexec |
| @@ -3120,7 +3120,7 @@ class runQueuePipe(): | |||
| 3120 | 3120 | ||
| 3121 | start = len(self.queue) | 3121 | start = len(self.queue) |
| 3122 | try: | 3122 | try: |
| 3123 | self.queue = self.queue + (self.input.read(102400) or b"") | 3123 | self.queue.extend(self.input.read(102400) or b"") |
| 3124 | except (OSError, IOError) as e: | 3124 | except (OSError, IOError) as e: |
| 3125 | if e.errno != errno.EAGAIN: | 3125 | if e.errno != errno.EAGAIN: |
| 3126 | raise | 3126 | raise |
