You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
String literals are not interned if in a tuple #70336
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2016-09-25.10:44:49.457>created_at=<Date2016-01-18.20:09:48.624>labels= ['interpreter-core', 'performance']
title='String literals are not interned if in a tuple'updated_at=<Date2016-09-25.10:44:49.456>user='https://github.com/serhiy-storchaka'
Usually string literals are interned. But not if they are a part of constant tuple.
>>> defabc(): pass
...
>>> x ='abc'
>>> x is abc.__name__
True
>>> x = ('abc',)
>>> x[0] is abc.__name__
False
This makes effect on namedtuples (bpo-25981). May make effect on __slots__ or other uses of constant tuples since searching a value in a tuple when values are not identical is a little slower that when they are identical.
Activity
serhiy-storchaka commentedon Jan 18, 2016
Usually string literals are interned. But not if they are a part of constant tuple.
This makes effect on namedtuples (bpo-25981). May make effect on __slots__ or other uses of constant tuples since searching a value in a tuple when values are not identical is a little slower that when they are identical.
vstinner commentedon Jan 19, 2016
FYI fatoptimizer has a more efficient algorithm to merge constants:
http://fatoptimizer.readthedocs.org/en/latest/optimizations.html#comparison-with-the-peephole-optimizer
It looks like it interns strings which are part of tuples. To be honest, I don't understand how it works, but it works :-)
serhiy-storchaka commentedon Sep 25, 2016
The patch is provided in bpo-27942.