[Python-checkins] r63059 - in python/trunk: Lib/test/test_marshal.py Python/marshal.c

andrew.kuchling python-checkins at python.org
Sun May 11 15:33:56 CEST 2008


Author: andrew.kuchling
Date: Sun May 11 15:33:56 2008
New Revision: 63059

Log:
#1792: Improve performance of marshal.dumps() on large objects by increasing
the size of the buffer more quickly.

Modified:
   python/trunk/Lib/test/test_marshal.py
   python/trunk/Python/marshal.c

Modified: python/trunk/Lib/test/test_marshal.py
==============================================================================
--- python/trunk/Lib/test/test_marshal.py	(original)
+++ python/trunk/Lib/test/test_marshal.py	Sun May 11 15:33:56 2008
@@ -255,6 +255,14 @@
             subtyp = type('subtyp', (typ,), {})
             self.assertRaises(ValueError, marshal.dumps, subtyp())
 
+    # Issue #1792 introduced a change in how marshal increases the size of its
+    # internal buffer; this test ensures that the new code is exercised.
+    def test_large_marshal(self):
+        size = int(1e6)
+        testString = 'abc' * size
+        marshal.dumps(testString)
+
+
 def test_main():
     test_support.run_unittest(IntTestCase,
                               FloatTestCase,

Modified: python/trunk/Python/marshal.c
==============================================================================
--- python/trunk/Python/marshal.c	(original)
+++ python/trunk/Python/marshal.c	Sun May 11 15:33:56 2008
@@ -65,7 +65,10 @@
 	if (p->str == NULL)
 		return; /* An error already occurred */
 	size = PyString_Size(p->str);
-	newsize = size + 1024;
+	newsize = size + size + 1024;
+	if (newsize > 32*1024*1024) {
+		newsize = size + 1024*1024;
+	}
 	if (_PyString_Resize(&p->str, newsize) != 0) {
 		p->ptr = p->end = NULL;
 	}


More information about the Python-checkins mailing list