This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2016年09月02日 16:45 by Kay.Hayen, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| intern_string_constants.patch | serhiy.storchaka, 2016年09月25日 10:37 | review | ||
| refleak.patch | yselivanov, 2016年11月09日 13:47 | review | ||
| Messages (15) | |||
|---|---|---|---|
| msg274257 - (view) | Author: Kay Hayen (Kay.Hayen) | Date: 2016年09月02日 16:45 | |
Consider this: def defaultKeepsIdentity(arg = "str_value"): print(arg is "str_value") defaultKeepsIdentity() This has been outputing "True" on every Python release I have seen so far, but not so on 3.6.0a4. Normally string values come from a "co_const" and will be "is" identical if used as literals in a module, but no longer in this case. This seems wasteful at best, needlessly increasing the number of strings in usage. Yours, Kay |
|||
| msg274262 - (view) | Author: Steven D'Aprano (steven.daprano) * (Python committer) | Date: 2016年09月02日 17:19 | |
Can confirm the expected behaviour (printing True) in Python 2.4 through 2.7, 3.3, Jython 2.5, and even venerable old Python 1.5 (where it prints 1). But *not* IronPython 2.6, where it prints False. In 3.6, the difference seems to be here: py> f = defaultKeepsIdentity py> f.__defaults__[0] is f.__code__.co_consts[1] False py> f.__defaults__[0] == f.__code__.co_consts[1] True This behaviour is not specified by the language. Caching and re-use of strings has always been subject to change. Nevertheless, perhaps it is time for this to be make a language feature: inside a function, any use of the same string literal should use the same object? |
|||
| msg274263 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年09月02日 17:23 | |
This likely is an interference of issue27095 with issue26148. I consider this as a regression. This causes not only a waste of memory, but can affect a performance, since comparing non-identical strings is slower than comparing identical strings. |
|||
| msg277313 - (view) | Author: Kay Hayen (kayhayen) | Date: 2016年09月24日 08:03 | |
Same with 3.6b1, still present. |
|||
| msg277323 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2016年09月24日 17:39 | |
It would be nice to get this fixed. |
|||
| msg277359 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年09月25日 10:37 | |
Proposed patch interns string constants recursively in tuples and frozensets. This fixes issue26148 and issue25981. |
|||
| msg277748 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年09月30日 07:40 | |
New changeset 78bea78d9335 by Serhiy Storchaka in branch '3.5': Issue #27942: String constants now interned recursively in tuples and frozensets. https://hg.python.org/cpython/rev/78bea78d9335 New changeset 0ce63a7651b9 by Serhiy Storchaka in branch '3.6': Issue #27942: String constants now interned recursively in tuples and frozensets. https://hg.python.org/cpython/rev/0ce63a7651b9 New changeset 44af6bd21b94 by Serhiy Storchaka in branch 'default': Issue #27942: String constants now interned recursively in tuples and frozensets. https://hg.python.org/cpython/rev/44af6bd21b94 New changeset 7cea3bf44acb by Serhiy Storchaka in branch '2.7': Issue #27942: String constants now interned recursively in tuples and frozensets. https://hg.python.org/cpython/rev/7cea3bf44acb |
|||
| msg277749 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年09月30日 07:57 | |
Thanks Naoki and Josh for reviews. Backported to 2.7 and 3.5 since the patch also fixes other issues. Note that the result of ``arg is "str_value"`` is implementation detail. Other Python implementations may not intern string constants. Even CPython interns only strings constants consisting of ASCII alphanumerical characters. |
|||
| msg280395 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 13:47 | |
The patch is causing refleaks: test_ast leaked [98, 98, 98] references, sum=294 test_code leaked [2, 2, 2] references, sum=6 Please review the attached patch fixing that. Please review. |
|||
| msg280399 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 14:37 | |
Looks like the attached patch also fixes test_trace leaked [12, 12, 12] references, sum=36 |
|||
| msg280400 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年11月09日 14:37 | |
Good catch! The patch LGTM, thanks Yury. Interesting, what tests in test_ast leak? I expected that this branch is executed in rare circumstances. |
|||
| msg280401 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 14:38 | |
> Interesting, what tests in test_ast leak? I expected that this branch is executed in rare circumstances. The test that tests it all :) test_stdlib_validates |
|||
| msg280402 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2016年11月09日 14:43 | |
New changeset 41613bb27f80 by Yury Selivanov in branch '2.7': Issue #27942: Fix memory leak in codeobject.c https://hg.python.org/cpython/rev/41613bb27f80 New changeset 2c6825c9ecfd by Yury Selivanov in branch '3.5': ssue #27942: Fix memory leak in codeobject.c https://hg.python.org/cpython/rev/2c6825c9ecfd New changeset b671ac7ae620 by Yury Selivanov in branch '3.6': Merge 3.5 (issue #27942) https://hg.python.org/cpython/rev/b671ac7ae620 New changeset c27269c0d619 by Yury Selivanov in branch 'default': Merge 3.6 (issue #27942) https://hg.python.org/cpython/rev/c27269c0d619 |
|||
| msg280403 - (view) | Author: Yury Selivanov (yselivanov) * (Python committer) | Date: 2016年11月09日 14:44 | |
Thanks for the review, Serhiy! |
|||
| msg280404 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2016年11月09日 14:53 | |
> The test that tests it all :) test_stdlib_validates :) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:35 | admin | set | github: 72129 |
| 2017年12月19日 08:50:39 | serhiy.storchaka | set | pull_requests: - pull_request1087 |
| 2017年03月31日 16:36:36 | dstufft | set | pull_requests: + pull_request1087 |
| 2016年11月09日 14:53:59 | serhiy.storchaka | set | messages: + msg280404 |
| 2016年11月09日 14:44:24 | yselivanov | set | priority: release blocker -> normal status: open -> closed resolution: fixed messages: + msg280403 |
| 2016年11月09日 14:43:46 | python-dev | set | messages: + msg280402 |
| 2016年11月09日 14:38:49 | yselivanov | set | messages: + msg280401 |
| 2016年11月09日 14:37:18 | serhiy.storchaka | set | messages: + msg280400 |
| 2016年11月09日 14:37:18 | yselivanov | set | messages: + msg280399 |
| 2016年11月09日 13:47:20 | yselivanov | set | status: closed -> open files: + refleak.patch nosy: + ned.deily, benjamin.peterson, yselivanov, larry messages: + msg280395 resolution: fixed -> (no value) priority: normal -> release blocker |
| 2016年09月30日 07:57:46 | serhiy.storchaka | set | status: open -> closed versions: + Python 2.7, Python 3.5 messages: + msg277749 resolution: fixed stage: patch review -> resolved |
| 2016年09月30日 07:40:02 | python-dev | set | nosy:
+ python-dev messages: + msg277748 |
| 2016年09月30日 06:12:45 | josh.r | set | nosy:
+ josh.r |
| 2016年09月29日 13:12:14 | serhiy.storchaka | set | assignee: serhiy.storchaka |
| 2016年09月25日 10:44:49 | serhiy.storchaka | link | issue26148 superseder |
| 2016年09月25日 10:37:35 | serhiy.storchaka | set | files:
+ intern_string_constants.patch versions: + Python 3.7 messages: + msg277359 keywords: + patch stage: patch review |
| 2016年09月24日 17:39:13 | rhettinger | set | nosy:
+ rhettinger messages: + msg277323 |
| 2016年09月24日 08:03:24 | kayhayen | set | nosy:
+ kayhayen messages: + msg277313 |
| 2016年09月02日 17:23:12 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg274263 |
| 2016年09月02日 17:19:50 | steven.daprano | set | nosy:
+ steven.daprano messages: + msg274262 |
| 2016年09月02日 16:45:37 | Kay.Hayen | create | |