[Python-Dev] undesireable unpickle behavior, proposed fix

Guido van Rossum guido at python.org
Tue Jan 27 20:57:46 CET 2009

On Tue, Jan 27, 2009 at 11:40 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> Hm. This would change the pickling format though. Wouldn't just
>> interning (short) strings on unpickling be simpler?
> Sure - that's what Jake had proposed. However, it is always difficult
> to select which strings to intern - his heuristics (IIUC) is to intern
> all strings that appear as dictionary keys. Whether this is good enough,
> I don't know. In particular, it might intern very large strings that
> aren't identifiers at all.

Just set a size limit, e.g. 30 or 100. It's just a heuristic. I
believe somewhere in Python itself I intern string literals if they
are reasonably short and fit the pattern of an identifier; I'd worry
that the pattern matching would slow down unpickling more than the
expected benefit though, so perhaps just a size test would be better.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list