◐ Shell
clean mode source ↗

Issue 26148: String literals are not interned if in a tuple

Issue26148

Created on 2016-01-18 20:09 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg258542 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-18 20:09
Usually string literals are interned. But not if they are a part of constant tuple.

>>> def abc(): pass
... 
>>> x = 'abc'
>>> x is abc.__name__
True
>>> x = ('abc',)
>>> x[0] is abc.__name__
False

This makes effect on namedtuples (issue25981). 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.
msg258594 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-19 13:58
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 :-)
msg277361 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-25 10:44
The patch is provided in issue27942.
History
Date User Action Args
2022-04-11 14:58:26adminsetgithub: 70336
2016-09-25 10:44:49serhiy.storchakasetstatus: open -> closed
superseder: Default value identity regression
messages: + msg277361

resolution: duplicate
stage: resolved

2016-04-26 08:51:12serhiy.storchakalinkissue25981 superseder
2016-01-19 13:58:38vstinnersetmessages: + msg258594
2016-01-19 13:41:24vstinnersetversions: + Python 3.6
2016-01-19 13:41:17vstinnersettype: performance
2016-01-18 20:09:48serhiy.storchakacreate