Apart the minor issues I saw, I think the patch is good. Just add a ...
15 years, 8 months ago
(2009-04-05 08:58:15 UTC)
#2
Apart the minor issues I saw, I think the patch is good. Just add a limit on the
internal buffer size and the patch will be ready to be committed.
By the way, most of your changes will not be necessary for Python 3.0. Do like
the simplification of Pickler_Write and the separation of the flush operation in
its own function. Your patch also gave me an optimization idea for _pickle in
Python 3.0 — i.e., re-implement pickle.dumps using unlimited internal buffering
of Pickler.
http://codereview.appspot.com/33070/diff/3/4
File Modules/cPickle.c (left):
http://codereview.appspot.com/33070/diff/3/4#oldcode226
Line 226: nbytes = (size_t)bigger * sizeof(PyObject *);
I agree that this is unlikely to overflow. :-)
http://codereview.appspot.com/33070/diff/3/4
File Modules/cPickle.c (right):
http://codereview.appspot.com/33070/diff/3/4#newcode176
Line 176: self->data = PyMem_NEW(PyObject *, self->size);
You probably should use PyMem_Malloc() and do the (PyObject *) manually, instead
of using the obsolete PyMem_NEW interface.
http://codereview.appspot.com/33070/diff/3/4#newcode348
Line 348:
I kinda like the idea of Antoine of using _PyString_Join(). The only problem is
you could ends up with a very large string copy in memory. So, you would need to
keep track of the total length of the strings kept.
Also, I agree that there should be a limit on the buffer length when Pickler is
used with streams.
http://codereview.appspot.com/33070/diff/3/4#newcode467
Line 467: Py_DECREF(output);
I think:
Py_DECREF(output);
if (ret == NULL)
return -1;
Py_DECREF(ret);
return 0;
would be at least as efficient and slightly less magic.
http://codereview.appspot.com/33070/diff/3/4#newcode2633
Line 2633: if (_Pickler_Write(self, NULL, 0) < 0)
What does this do? The original cPickle interprets NULL to mean flush the
buffer, but I don't think this is what you want.
http://codereview.appspot.com/33070/diff/3/4 File Modules/cPickle.c (right): http://codereview.appspot.com/33070/diff/3/4#newcode348 Line 348: Thinking about it, building lots of small PyStrings ...
15 years, 8 months ago
(2009-04-05 15:20:02 UTC)
#3
Issue 33070: Speed up cPickle's internal output machinery
Created 15 years, 9 months ago by Collin Winter
Modified 15 years, 8 months ago
Reviewers: Antoine Pitrou, Alexandre Vassalotti
Base URL: http://svn.python.org/view/*checkout*/python/trunk/
Comments: 11