]> granicus.if.org Git - python/commitdiff
#1792: Improve performance of marshal.dumps() on large objects by increasing
authorAndrew M. Kuchling <amk@amk.ca>
Sun, 11 May 2008 13:33:56 +0000 (13:33 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Sun, 11 May 2008 13:33:56 +0000 (13:33 +0000)
the size of the buffer more quickly.

Lib/test/test_marshal.py
Python/marshal.c

index 1b2c8b7162968d3ceb24388e626fa6c6bf6a000f..943aa55b39a8aeddd69f4d0a4cb868aef62c1678 100644 (file)
@@ -255,6 +255,14 @@ class BugsTestCase(unittest.TestCase):
             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,
index 6ca3495707d4a61dd8d9be1d3e22ba71286984ff..6db46e4f6382b7ace855f326785f364cddf15c87 100644 (file)
@@ -65,7 +65,10 @@ w_more(int c, WFILE *p)
        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;
        }