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) * ![]() |
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) * ![]() |
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) * ![]() |
Date: 2016-09-25 10:44 | |
The patch is provided in issue27942. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:26 | admin | set | github: 70336 |
| 2016-09-25 10:44:49 | serhiy.storchaka | set | status: open -> closed superseder: Default value identity regression messages: + msg277361 resolution: duplicate |
| 2016-04-26 08:51:12 | serhiy.storchaka | link | issue25981 superseder |
| 2016-01-19 13:58:38 | vstinner | set | messages: + msg258594 |
| 2016-01-19 13:41:24 | vstinner | set | versions: + Python 3.6 |
| 2016-01-19 13:41:17 | vstinner | set | type: performance |
| 2016-01-18 20:09:48 | serhiy.storchaka | create | |
