[Python-Dev] Interning string subtype instances

"Martin v. Löwis" martin at v.loewis.de
Wed Feb 14 09:08:29 CET 2007


Greg Ewing schrieb:
> It's certainly possible to tell very easily whether
> a string is interned -- there's a PyString_CHECK_INTERNED
> macro that tests a field in the string object header.
> But, I can't find anywhere that it's used in the core,
> apart from the interning code itself and the string
> alloc/dealloc code.
> 
> Can anyone shed any light on this? It seems to me that
> by not using this information, only half the benefit of
> interning is being achieved.

You seem to assume that checking this property would improve
performance. I find that questionable; as always with performance
and optimization, one cannot know until it has been benchmarked.

My guess is that
- the cases you want to cover are comparably infrequent
   (compared to the total number of richcompare invocations)
- checking the additional field always may cause a performance
   loss, not a performance gain, because of the additional
   tests.

If you want to sure, you need to make some measurements
(e.g: what is the percentage of EQ and NE invocations,
  in how many cases are both strings interned, and in
  what percentage of these cases are they not the same
  string).

Regards,
Martin


More information about the Python-Dev mailing list