changeset 766:c8810dc507f3

Fixed memory leak. It turned out that we kept references to empty deques in incoming_data without ever releasing them. This caused the memory usage to grow as more and more communication was done. Checking for empty deques every time something is received or sent is expensive -- I measured a performance drop of 25%! To make things worse, I observed that the deques are mostly empty, so we are probably deleting and recreating them all the time. Patches with optimizations are very welcome! :-)
author Martin Geisler <>
date Tue, 20 May 2008 14:18:27 +0200
parents 563bcc37fe47
children f993269c2660
files viff/
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/	Tue May 20 14:13:33 2008 +0200
+++ b/viff/	Tue May 20 14:18:27 2008 +0200
@@ -288,6 +288,8 @@
             deq = self.incoming_data.setdefault(key, deque())
             if deq and isinstance(deq[0], Deferred):
                 deferred = deq.popleft()
+                if not deq:
+                    del self.incoming_data[key]
@@ -556,6 +558,8 @@
         if deq and not isinstance(deq[0], Deferred):
             # We have already received some data from the other side.
             data = deq.popleft()
+            if not deq:
+                del self.protocols[peer_id].incoming_data[key]
             # We have not yet received anything from the other side.