Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-85160: Optimized singledispatchmethod access (noticeable improvement).#23213

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mental32 wants to merge2 commits intopython:mainfrommental32:bpo-40988
Closed

Conversation

@mental32
Copy link
Contributor

@mental32mental32 commentedNov 10, 2020
edited by bedevere-bot
Loading

I benchmarked using the following code:

fromfunctoolsimportsingledispatch,singledispatchmethodimporttimeitclassTest:@singledispatchmethoddefgo(self,item,arg):print('general')@go.registerdef_(self,item:int,arg):returnitem+arg@singledispatchdefgo(item,arg):print('general')@go.registerdef_(item:int,arg):returnitem+argprint('m',timeit.timeit('t.go(1, 1)',globals={'t':Test()}))print('s',timeit.timeit('go(1, 1)',globals={'go':go}))

And got the following output:

mental@felix ~/D/o/cpython (master)> ./python /tmp/fdsm.pym 4.794188453000061s 0.9868643390000216mental@felix ~/D/o/cpython (master)> git checkout 40988Switched to branch '40988'mental@felix ~/D/o/cpython (40988) [1]> ./python /tmp/fdsm.pym 1.3791182540007867s 0.9882650030003788

I'm still curious if access could be further optimized clueless when it comes to ideas 😅

https://bugs.python.org/issue40988

@mental32mental32 changed the titlebpo-40988: Optimized singledispatchmethod access (3x ish improvement).bpo-40988: Optimized singledispatchmethod access (noticeable improvement).Nov 10, 2020
@CaselIT
Copy link

Thanks for taking this up!

mental32 reacted with thumbs up emoji

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelDec 16, 2020
@CaselIT
Copy link

Comment to avoid closure

mental32 reacted with thumbs up emoji

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelDec 17, 2020
@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelJan 16, 2021
@mental32
Copy link
ContributorAuthor

@rhettinger sorry for bothering you but do you have enough bandwidth to review this or can you defer to someone else?

CaselIT reacted with thumbs up emoji

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelJan 17, 2021
@CaselIT
Copy link

Not sure if there is anything we should do to allow this to be reviewed

@rhettingerrhettinger removed their request for reviewMay 3, 2022 06:14
Copy link
Contributor

@MaxwellDupreMaxwellDupre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

On my slow system more modest, but an improvement:
11.24
2.27
to
5.83
3.54
I not that this is built on 3.10.0a2+ so there maybe further speed improvements when 3.11/3.12 is released. So a worthwhile change.

@TeamSpen210
Copy link

Since this is something that’ll have observable effects on objects, should this be documented? If you’re introspecting your objects, or are say concerned about memory usage it might be surprising behaviour.

@AlexWaygoodAlexWaygood changed the titlebpo-40988: Optimized singledispatchmethod access (noticeable improvement).gh-85160: Optimized singledispatchmethod access (noticeable improvement).Jul 5, 2023
@eendebakpt
Copy link
Contributor

@mental32@AlexWaygood By accident I created an independent implementation of the singledispatchmethod improvement. In#106448 I added a performance comparison of this PR and the other one. I also added a test for the case of a class with slots (commit4e068d4). Feel free to pull that one into this branch.

Both branches give a performance improvement over current main. Hopefully one of them gets accepted.

Comment on lines +957 to +963
ifself.attrnameisnotNone:
attrname=self.attrname

try:
obj.__dict__[attrname]=_method
exceptAttributeError:
pass# not all objects have __dict__ (e.g. class defines slots)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
ifself.attrnameisnotNone:
attrname=self.attrname
try:
obj.__dict__[attrname]=_method
exceptAttributeError:
pass# not all objects have __dict__ (e.g. class defines slots)
ifself.attrnameisnotNone:
try:
obj.__dict__[self.attrname]=_method
exceptAttributeError:
pass# not all objects have __dict__ (e.g. class defines slots)

@corona10corona10 self-assigned thisJul 21, 2023
@mental32
Copy link
ContributorAuthor

mental32 commentedJul 26, 2023
edited
Loading

@eendebakpt thank you for continuing with this!

for any changes or merging that you would like to see done is it okay for me to say "do whatever you need to do :)" and defer to you? (including closing this PR if the other one is sufficient in perf improvements) I don't think I have the time to pay attention to this is all

@AlexWaygood
Copy link
Member

Closing in favour of#107148 (in which you have been listed as a co-author :)

mental32 reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eendebakpteendebakpteendebakpt left review comments

+1 more reviewer

@MaxwellDupreMaxwellDupreMaxwellDupre approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

@corona10corona10

Labels

awaiting core reviewperformancePerformance or resource usage

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

11 participants

@mental32@CaselIT@TeamSpen210@eendebakpt@AlexWaygood@MaxwellDupre@iritkatriel@corona10@the-knights-who-say-ni@ezio-melotti@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp