-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-28638: Optimize namedtuple() creation time by minimizing use of exec() #3454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
baca675
3a2aa41
e24ef4b
49aa967
c34b444
0c7f163
5de0b7f
ca643f4
e18b92e
0851fc7
3ac1151
b31f063
deb30a2
f402cb3
86cef9e
83b5e93
0168317
dadafc0
483d08c
bc6852c
c897674
bd4ea4e
ffb78c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,12 @@ API and Feature Removals | |
Python 3.1, and has now been removed. Use the :func:`~os.path.splitdrive` | ||
function instead. | ||
|
||
* :func:`collections.namedtuple` no longer supports the *verbose* parameter | ||
or ``_source`` attribute which showed the generated source code for the | ||
named tuple class. This was part of an optimization designed to speed-up | ||
class creation. (Contributed by Jelle Zijlstra with further improvements | ||
by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger in :issue:`28638`.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose here should be "Naoki Inada" instead of "INADA Naoki". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps. That is for him to decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I don't care in general, I prefer "INADA Naoki" here because I use it in git config "user.name". |
||
|
||
* Functions :func:`bool`, :func:`float`, :func:`list` and :func:`tuple` no | ||
longer take keyword arguments. The first argument of :func:`int` can now | ||
be passed only as positional argument. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Changed the implementation strategy for collections.namedtuple() to | ||
substantially reduce the use of exec() in favor of precomputed methods. As a | ||
result, the *verbose* parameter and *_source* attribute are no longer | ||
supported. The benefits include 1) having a smaller memory footprint for | ||
applications using multiple named tuples, 2) faster creation of the named | ||
tuple class (approx 4x to 6x depending on how it is measured), and 3) minor | ||
speed-ups for instance creation using __new__, _make, and _replace. (The | ||
primary patch contributor is Jelle Zijlstra with further improvements by | ||
INADA Naoki, Serhiy Storchaka, and Raymond Hettinger.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is worth to add a note about an optimization in the "Optimizations" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to litter the docs with more notes about this. The more important part to note is the feature removal in whatsnew. The optimization is mostly negligible and insignificant to most users (normal startup doesn't use named tuples at all; a module using one named tuple was using only 0.3ms which was just under 1% of the overall start-up time; formerly, we could make 3 namedtuple classes per millisecond and now we can make about 15). It is one of the least important optimizations we could have done.