[Python-3000] inst_persistent_id

Jim Fulton jim at zope.com
Sat Jan 12 18:25:00 CET 2008


Recently, I reviewed the documentation source for pickle and came  
across the following comment:

    BAW: Both pickle and cPickle support something called  
inst_persistent_id()
    which appears to give unknown types a second shot at producing a  
persistent
    id.  Since Jim Fulton can't remember why it was added or what it's  
for, I'm
    leaving it undocumented.

I couldn't remember this and decided to dig into it and realized that  
this was a very useful experimental feature I added way back when  
cPickle was in its infancy.  This is a fairly useful optimization that  
I never got around to evaluating.  (Yeah, I know.) It is a hook, like  
the persistent_id hook that is called with objects to determine if  
they should be pickled by persistent reference.  Unlike persistent_id,  
it isn't called for built-in types (really types for which pickle has  
specific handlers), like strings, numbers, lists, tuples and so on. It  
is only called for "instances" (types for which pickle doesn't have  
specific handlers).  This vastly reduces the number of calls to the  
hook.  Some tests with ZODB indicated significant improvements in  
pickling speed when a hook is used.

If there are no objections, I'll update the Python 2 documentation to  
describe this and add a test.  The comment above suggests that this  
hook is in pickle and cPickle.  It is in cPickle, but was removed from  
pickle.  I propose to add it back to pickle -- mainly for consistency  
with cPickle.  I'll need to double check how this interacts with the  
type dispatching in pickle protocol 2.

Any objections?

Jim

--
Jim Fulton
Zope Corporation




More information about the Python-3000 mailing list