Uh oh!
There was an error while loading. Please reload this page.
bpo-44953: Add vectorcall for itemgetter and attrgetter - #27828
Conversation
sweeneyde
commented
Aug 19, 2021
This was inspired by GH-27782, which does the same, and more, for methodcaller. |
sweeneyde
commented
Aug 19, 2021
Benchmarks for this change: |
bedevere-bot
commented
Aug 20, 2021
🤖 New build scheduled with the buildbot fleet by @rhettinger for commit f9fc83a 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This PR is stale because it has been open for 30 days with no activity. |
sweeneyde
commented
Oct 2, 2021
The |
Any plans for this? It may also be relevant to bpo-46148 about optimizing Pathlib. |
sweeneyde
commented
Jan 23, 2022
Does anyone with a commit bit want to merge this? This is the kind of callable that's often called in loops. |
sweeneyde
commented
Feb 10, 2022
I re-ran some benchmarks, and they still look good. I plan to merge this in about 24 hours if there are no more objections. fromoperatorimportitemgetter, attrgetterfromitertoolsimportrepeatfromcollectionsimportnamedtuple, dequefrompyperfimportRunnerclassDefaultClass:
def__init__(self, a, b):
self.a=aself.b=bclassSlotsClass:
__slots__="a", "b"def__init__(self, a, b):
self.a=aself.b=bNamedTuple=namedtuple("NT", ["a", "b"])
MAP_LOOPS=10_000attr_classes= {
'DefaultClass': DefaultClass,
'SlotsClass': SlotsClass,
'NamedTuple': NamedTuple,
}
item_classes= {
'tuple': tuple,
'list': list,
'dict': dict.fromkeys,
}
namespace= {
'IG': itemgetter(1),
'AG': attrgetter('a'),
'repeat': repeat,
'deque': deque,
} |attr_classes|item_classesrunner=Runner()
forclassnameinattr_classes:
runner.timeit(
name=f"{classname}-1",
setup=f"obj = {classname}(11, 22)",
stmt="AG(obj)",
globals=namespace
)
runner.timeit(
name=f"{classname}-map",
setup=f"obj = {classname}(11, 22)",
stmt=f"deque(map(AG, repeat(obj, {MAP_LOOPS})), maxlen=0)",
globals=namespace,
inner_loops=MAP_LOOPS,
)
forclassnameinitem_classes:
runner.timeit(
name=f"{classname}-1",
setup=f"obj = {classname}((1, 2, 3, 4, 5))",
stmt="IG(obj)",
globals=namespace,
)
runner.timeit(
name=f"{classname}-map",
setup=f"obj = {classname}((1, 2, 3, 4, 5))",
stmt=f"deque(map(IG, repeat(obj, {MAP_LOOPS})), maxlen=0)",
globals=namespace,
inner_loops=MAP_LOOPS,
)Results:
|
https://bugs.python.org/issue44953