Please sign in to comment.
bpo-28638: Optimize namedtuple() creation time by minimizing use of e…
…xec() (#3454) * Working draft without _source * Re-use itemgetter() instances * Speed-up calls to __new__() with a pre-bound tuple.__new__() * Add note regarding string interning * Remove unnecessary create function wrappers * Minor sync-ups with PR-2736. Mostly formatting and f-strings * Bring-in qualname/__module fix-ups from PR-2736 * Formally remove the verbose flag and _source attribute * Restore a test of potentially problematic field names * Restore kwonly_args test but without the verbose option * Adopt Inada's idea to reuse the docstrings for the itemgetters * Neaten-up a bit * Add news blurb * Serhiy pointed-out the need for interning * Jelle noticed as missing f on an f-string * Add whatsnew entry for feature removal * Accede to request for dict literals instead keyword arguments * Leave the method.__module__ attribute pointing the actual location of the code * Improve variable names and add a micro-optimization for an non-public helper function * Simplify by in-lining reuse_itemgetter() * Arrange steps in more logical order * Save docstring in local cache instead of interning
- Loading branch information...
Showing with 136 additions and 113 deletions.
|@@ -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.)|