From d28a7bfb862e6d9b9716098b27e5ec1d2f482da8 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 19 Oct 2017 09:02:33 +0200 Subject: [PATCH] Asyncore performance optimisation - don't transfer unnecessary amount of bytes from network buffers - slice buffer more efficiently if it results in an empty buffer --- src/network/advanceddispatcher.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/network/advanceddispatcher.py b/src/network/advanceddispatcher.py index 331daf03..97481238 100644 --- a/src/network/advanceddispatcher.py +++ b/src/network/advanceddispatcher.py @@ -36,12 +36,18 @@ class AdvancedDispatcher(asyncore.dispatcher): def slice_write_buf(self, length=0): if length > 0: with self.writeLock: - del self.write_buf[0:length] + if length >= len(self.write_buf): + del self.write_buf[:] + else: + del self.write_buf[0:length] def slice_read_buf(self, length=0): if length > 0: with self.readLock: - del self.read_buf[0:length] + if length >= len(self.read_buf): + del self.read_buf[:] + else: + del self.read_buf[0:length] def process(self): if not self.connected: @@ -77,7 +83,7 @@ class AdvancedDispatcher(asyncore.dispatcher): if asyncore.maxDownloadRate > 0: self.downloadChunk = asyncore.downloadBucket try: - if self.expectBytes > 0 and not self.fullyEstablished: + if self.expectBytes > 0: self.downloadChunk = min(self.downloadChunk, self.expectBytes - len(self.read_buf)) if self.downloadChunk < 0: self.downloadChunk = 0