Optimization of Tuples and Strings

Matt Gerrans mgerrans at mindspring.com
Mon Jan 7 17:22:16 EST 2002


Thanks to you all for the informative replies!   I had forgotten about the
'is' operator and didn't know about id().

It looks to me like I'll have to build a hash myself to ensure that identical
objects are shared; I have a two large collections of lists, many of which are
identical (within each collection).    The two collections are read in at
runtime and each element compared to each element of the other, so you can
imagine the performance quickly plummets as the scale increases.

As you might imagine, I was hoping to simply change the lists to tuples, for
the 'automatic' optimization, but it looks like I don't get that shortcut.
That's okay, writing the cache should be easy enough and fun (I'm already
thinking of an additional optimization I can add based on the relationship of
the data in the two collections...).

- Matt





More information about the Python-list mailing list