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.

classification
Title: Add vectorcall on operator.itemgetter and attrgetter objects
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney
Priority: normal Keywords: patch

Created on 2021-08-19 09:23 by Dennis Sweeney, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27828 merged Dennis Sweeney, 2021-08-19 09:24
PR 31265 merged Dennis Sweeney, 2022-02-10 22:39
Messages (3)
msg399900 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-08-19 09:23
## Below are my benchmarks for this change.

from operator import itemgetter, attrgetter
from pyperf import Runner

class MyClass:
    __slots__ = "a", "b"

namespace = {'itemgetter': itemgetter,
             'attrgetter': attrgetter,
             'MyClass': MyClass,
             }

runner = Runner()
runner.timeit(
    name="itemgetter",
    setup="f = itemgetter(1); x = (1, 2, 3)",
    stmt="f(x)",
    globals=namespace
)
runner.timeit(
    name="attrgetter",
    setup="f = attrgetter('b'); x = MyClass(); x.a = x.b = 1",
    stmt="f(x)",
    globals=namespace
)

##### Results #####
# itemgetter: Mean +- std dev: [operator_main] 45.3 ns +- 1.3 ns -> [operator_vec] 29.5 ns +- 0.7 ns: 1.54x faster
# attrgetter: Mean +- std dev: [operator_main] 61.6 ns +- 1.7 ns -> [operator_vec] 43.8 ns +- 0.9 ns: 1.41x faster
msg413026 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-10 21:58
New changeset 0a145069e807fdafd1fa0315b9bc22da363d2d39 by Dennis Sweeney in branch 'main':
bpo-44953: Add vectorcall for itemgetter and attrgetter instances (GH-27828)
https://github.com/python/cpython/commit/0a145069e807fdafd1fa0315b9bc22da363d2d39
msg413027 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-02-10 22:57
New changeset 035414a878a772d1d293cdecdc4470bcce5e5d7a by Dennis Sweeney in branch 'main':
bpo-44953: Add newline at end of NEWS entry (GH-31265)
https://github.com/python/cpython/commit/035414a878a772d1d293cdecdc4470bcce5e5d7a
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89116
2022-02-11 16:16:33Dennis Sweeneysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-10 22:57:28Dennis Sweeneysetmessages: + msg413027
2022-02-10 22:39:47Dennis Sweeneysetpull_requests: + pull_request29431
2022-02-10 21:58:08Dennis Sweeneysetmessages: + msg413026
2021-08-19 09:24:31Dennis Sweeneysetkeywords: + patch
stage: patch review
pull_requests: + pull_request26293
2021-08-19 09:23:49Dennis Sweeneycreate