Skip to content

Commit 3d37d30

Browse files
authored
Avoid buffer copies in worker
This increases peek download speed from about 850MB/s to 960MB/s on my computer. derrod#620
1 parent 4507842 commit 3d37d30

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

legendary/downloader/mp/workers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ def run(self):
126126

127127
# decompress stuff
128128
try:
129-
size = len(chunk.data)
129+
data = chunk.data
130+
size = len(data)
130131
if size > job.shm.size:
131132
logger.fatal('Downloaded chunk is longer than SharedMemorySegment!')
132133

133-
self.shm.buf[job.shm.offset:job.shm.offset + size] = bytes(chunk.data)
134+
self.shm.buf[job.shm.offset:job.shm.offset + size] = data
134135
del chunk
135136
self.o_q.put(DownloaderTaskResult(success=True, size_decompressed=size,
136137
size_downloaded=compressed, **job.__dict__))
@@ -271,7 +272,7 @@ def run(self):
271272
if j.shared_memory:
272273
shm_offset = j.shared_memory.offset + j.chunk_offset
273274
shm_end = shm_offset + j.chunk_size
274-
current_file.write(self.shm.buf[shm_offset:shm_end].tobytes())
275+
current_file.write(self.shm.buf[shm_offset:shm_end])
275276
elif j.cache_file:
276277
with open(os.path.join(self.cache_path, j.cache_file), 'rb') as f:
277278
if j.chunk_offset:

0 commit comments

Comments
 (0)