[PATCH] Remove unneeded workaround for Darwin

Sebastian Spaeth Sebastian at SSpaeth.de
Tue Mar 1 14:31:43 GMT 2011

There is a clumsy workaround for Darwin that chunks reads into 8kb
blocks to avoid huge memory allocations. First, this fix should not only
be required but on FreeBSD2.6 too (see
http://bugs.python.org/issue3531). Second, decent python versions (I
checked 2.6) already chunk in the SSL case anyway, so there is no need to do
that again. Remove that level of indirection.

http://evanjones.ca/python-memory.html claims that this problem has been
fixed since python 2.5, so we might consider removing the workaround
completely even for the non-SSL case.

Increase the chunk size on Mac from 8kb to 64kb. Even Macs should be
able to take that amount of memory usage nowadays.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
This is suitable and on top of the 'next' branch,
but is a very safe and local change.

 offlineimap/imapserver.py |   22 ++++------------------
 1 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 2a9f247..fa56af7 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -60,37 +60,23 @@ class UsefulIMAPMixIn:
         imaplibutil.new_mesg(self, s, secs)
 class UsefulIMAP4(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4):
     # This is a hack around Darwin's implementation of realloc() (which
     # Python uses inside the socket code). On Darwin, we split the
-    # message into 100k chunks, which should be small enough - smaller
-    # might start seriously hurting performance ...
+    # message into small chunks.
+    # see http://bugs.python.org/issue3531
     def read(self, size):
         if (system() == 'Darwin') and (size>0) :
             read = 0
             io = StringIO()
             while read < size:
-                data = imaplib.IMAP4.read (self, min(size-read,8192))
+                data = imaplib.IMAP4.read (self, min(size-read, 65536))
                 read += len(data)
             return io.getvalue()
             return imaplib.IMAP4.read (self, size)
-class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4_SSL):
-    # This is the same hack as above, to be used in the case of an SSL
-    # connexion.
-    def read(self, size):
-        if (system() == 'Darwin') and (size>0) :
-            read = 0
-            io = StringIO()
-            while read < size:
-                data = imaplibutil.WrappedIMAP4_SSL.read (self, min(size-read,8192))
-                read += len(data)
-                io.write(data)
-            return io.getvalue()
-        else:
-            return imaplibutil.WrappedIMAP4_SSL.read (self,size)
+class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4_SSL): pass
 class UsefulIMAP4_Tunnel(UsefulIMAPMixIn, imaplibutil.IMAP4_Tunnel): pass

More information about the OfflineIMAP-project mailing list