
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2016-09-02 16:45 byKay.Hayen, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| 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)*![]() | 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 = defaultKeepsIdentitypy> f.__defaults__[0] is f.__code__.co_consts[1]Falsepy> f.__defaults__[0] == f.__code__.co_consts[1]TrueThis 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)*![]() | Date: 2016-09-02 17:23 | |
This likely is an interference ofissue27095 withissue26148. 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)*![]() | Date: 2016-09-24 17:39 | |
It would be nice to get this fixed. | |||
| msg277359 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2016-09-25 10:37 | |
Proposed patch interns string constants recursively in tuples and frozensets. This fixesissue26148 andissue25981. | |||
| msg277748 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2016-09-30 07:40 | |
New changeset78bea78d9335 by Serhiy Storchaka in branch '3.5':Issue#27942: String constants now interned recursively in tuples and frozensets.https://hg.python.org/cpython/rev/78bea78d9335New changeset0ce63a7651b9 by Serhiy Storchaka in branch '3.6':Issue#27942: String constants now interned recursively in tuples and frozensets.https://hg.python.org/cpython/rev/0ce63a7651b9New changeset44af6bd21b94 by Serhiy Storchaka in branch 'default':Issue#27942: String constants now interned recursively in tuples and frozensets.https://hg.python.org/cpython/rev/44af6bd21b94New changeset7cea3bf44acb 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)*![]() | 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)*![]() | 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=6Please review the attached patch fixing that. Please review. | |||
| msg280399 -(view) | Author: Yury Selivanov (yselivanov)*![]() | 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)*![]() | 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)*![]() | 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)![]() | Date: 2016-11-09 14:43 | |
New changeset41613bb27f80 by Yury Selivanov in branch '2.7':Issue#27942: Fix memory leak in codeobject.chttps://hg.python.org/cpython/rev/41613bb27f80New changeset2c6825c9ecfd by Yury Selivanov in branch '3.5':ssue#27942: Fix memory leak in codeobject.chttps://hg.python.org/cpython/rev/2c6825c9ecfdNew changesetb671ac7ae620 by Yury Selivanov in branch '3.6':Merge 3.5 (issue#27942)https://hg.python.org/cpython/rev/b671ac7ae620New changesetc27269c0d619 by Yury Selivanov in branch 'default':Merge 3.6 (issue#27942)https://hg.python.org/cpython/rev/c27269c0d619 | |||
| msg280403 -(view) | Author: Yury Selivanov (yselivanov)*![]() | Date: 2016-11-09 14:44 | |
Thanks for the review, Serhiy! | |||
| msg280404 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | 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 | |