Browse Source
bpo-32492: 1.6x speed up in namedtuple attribute access using C fast-path (#10495)
bpo-32492: 1.6x speed up in namedtuple attribute access using C fast-path (#10495)
* bpo-32492: 2.5x speed up in namedtuple attribute access using C fast path * Add News entry * fixup! bpo-32492: 2.5x speed up in namedtuple attribute access using C fast path * Check for tuple in the __get__ of the new descriptor and don't cache the descriptor itself * Don't inherit from property. Implement GC methods to handle __doc__ * Add a test for the docstring substitution in descriptors * Update NEWS entry to reflect time against 3.7 branch * Simplify implementation with argument clinic, better error messages, only __new__ * Use positional-only parameters for the __new__ * Use PyTuple_GET_SIZE and PyTuple_GET_ITEM to tighter the implementation of tuplegetterdescr_get * Implement __set__ to make tuplegetter a data descriptor * Use Py_INCREF now that we inline PyTuple_GetItem * Apply the valid_index() function, saving one test * Move Py_None test out of the critical path.pull/11365/head
committed by
Raymond Hettinger
5 changed files with 211 additions and 4 deletions
-
14Lib/collections/__init__.py
-
8Lib/test/test_collections.py
-
2Misc/NEWS.d/next/Core and Builtins/2018-11-13-01-03-10.bpo-32492.voIdcp.rst
-
163Modules/_collectionsmodule.c
-
28Modules/clinic/_collectionsmodule.c.h
@ -0,0 +1,2 @@ |
|||
Speed up :class:`namedtuple` attribute access by 1.6x using a C fast-path |
|||
for the name descriptors. Patch by Pablo Galindo. |
|||
@ -0,0 +1,28 @@ |
|||
/*[clinic input] |
|||
preserve |
|||
[clinic start generated code]*/ |
|||
|
|||
static PyObject * |
|||
tuplegetter_new_impl(PyTypeObject *type, Py_ssize_t index, PyObject *doc); |
|||
|
|||
static PyObject * |
|||
tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
|||
{ |
|||
PyObject *return_value = NULL; |
|||
Py_ssize_t index; |
|||
PyObject *doc; |
|||
|
|||
if ((type == &tuplegetter_type) && |
|||
!_PyArg_NoKeywords("_tuplegetter", kwargs)) { |
|||
goto exit; |
|||
} |
|||
if (!PyArg_ParseTuple(args, "nO:_tuplegetter", |
|||
&index, &doc)) { |
|||
goto exit; |
|||
} |
|||
return_value = tuplegetter_new_impl(type, index, doc); |
|||
|
|||
exit: |
|||
return return_value; |
|||
} |
|||
/*[clinic end generated code: output=83746071eacc28d3 input=a9049054013a1b77]*/ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue