Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-44953: Add vectorcall for itemgetter and attrgetter#27828
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
sweeneyde commented Aug 19, 2021 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
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 |
sweeneyde commented Jan 3, 2022 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
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