-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-85160: improve performance of singledispatchmethod #107148
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
04fe64e
bpo-40988: Optimized singledispatchmethod access.
mental32 fc72bea
Merge branch 'main' into bpo-40988
AlexWaygood 31d292b
Merge branch 'main' into singledispatchmethod3
eendebakpt 5ae8348
add test for slotted classes
eendebakpt 1edc0e3
add test for slotted classes
eendebakpt 9a1ffae
update new entry with attribution to original author
eendebakpt 3588943
add test for assignment to dispatched methods
eendebakpt af233d4
typo
eendebakpt d5aebdf
Update Lib/test/test_functools.py
eendebakpt b773f82
apply review suggestion
eendebakpt 25e1915
Merge branch 'main' into singledispatchmethod3
eendebakpt 593c923
Update Lib/functools.py
eendebakpt 39bec6d
Update Lib/functools.py
eendebakpt d954244
use hasattr to check for slotted types
eendebakpt df2eeb5
make attrname private
eendebakpt 774ec3c
review comments
eendebakpt f03ebba
use weakref for caching
eendebakpt b459718
Merge branch 'singledispatchmethod3' of githubeendebakpt:eendebakpt/c…
eendebakpt a422989
Merge branch 'main' into singledispatchmethod3
eendebakpt 450ea12
make patchcheck
eendebakpt 032ab24
review comments
eendebakpt 18d7e43
Apply suggestions from code review
eendebakpt 755efdd
Merge branch 'main' into singledispatchmethod3
eendebakpt 56d342c
Ensure we only weakref() `obj` once
AlexWaygood a119e21
Get rid of the cache local variable
AlexWaygood 47c18a5
Don't assign `caching` in the fast path
AlexWaygood 2031680
Merge pull request #5 from AlexWaygood/even-more-singledispatchmethod…
eendebakpt ca691e8
remove check on obj being None
eendebakpt e8eeedd
eliminate caching variable
eendebakpt 307f0c1
Merge pull request #6 from eendebakpt/singledispatchmethod3b
eendebakpt afea7b9
Test slotted staticmethods on instances as well as the class
AlexWaygood b43dcee
eliminate method variable and reduce attribute lookups
eendebakpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2020-11-10-07-04-15.bpo-40988.5kBC-O.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Improve performance of :class:`functools.singledispatchmethod` by caching the | ||
generated dispatch wrapper. Optimization suggested by frederico. Patch by | ||
@mental32, Alex Waygood and Pieter Eendebak. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I wonder if this would have been a good idea, to keep memory usage down for the slow path (since in the slow path, we don't really need the
WeakKeyDictionary
at all)@corona10, what do you think? Does it matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could even delay the creation of the Weakkeydictionary untill the first invocation of
__get__
. The code will look a bit odd though, a simpledel
looks cleaner.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think I prefer the approach with
del