FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-31581: Reduce the number of imports for functools by methane · Pull Request #3757 · python/cpython · GitHub

/ cpython Public

bpo-31581: Reduce the number of imports for functools - #3757

Merged
methane merged 7 commits into
python:masterfrom
methane:bpo31518-functools-import
Sep 30, 2017
Merged

bpo-31581: Reduce the number of imports for functools#3757
methane merged 7 commits into
python:masterfrom
methane:bpo31518-functools-import

Conversation

methane commented Sep 26, 2017
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Since functools and collections are very commonly used, it's worth enough to optimize import.

https://bugs.python.org/issue31581

methane commented Sep 26, 2017

Copy link
Copy Markdown
Member Author

I added 'skip news' tag, since #1269 don't have news too.

ncoghlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The functools.singledispatch change seems reasonable to me, since the cost of checking the import cache twice will be cheap compared to the overhead of defining a new function to apply @singledispatch to.

As per the comments on the argparse PR, this should be accompanied by a comment explaining the trade-off (i.e. there are many programs that use functools without singledispatch, so we trade-off making singledispatch marginally slower for the benefit of making start-up of such applications slightly faster)

However, I'm less sure of the appropriateness of the start-up vs runtime cost trade-off for Counter.most_common, so I'd prefer to see that change in a separate PR.

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I didn't expect the Spanish Inquisition!. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

methane force-pushed the bpo31518-functools-import branch from a0082b6 to f228a84 Compare September 26, 2017 08:47
Comment thread Lib/functools.py Outdated
# There are many programs that use functools without singledispatch, so we
# trade-off making singledispatch marginally slower for the benefit of
# making start-up of such applications slightly faster.
from types import MappingProxyType

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is slightly faster to import types and use types.MappingProxyType once than import MappingProxyType from types. The from ... import case runs a Python code from _bootstrap.py, while the former case runs just a C code if the types module already is imported.

Comment thread Lib/test/test_functools.py Outdated
def clear(self):
self.data.clear()
_orig_wkd = functools.WeakKeyDictionary
_orig_wkd = weakref.WeakKeyDictionary

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Use try ... finally or test.support.swap_attr() for guaranteeing that weakref.WeakKeyDictionary is restored if the following checks fail.

methane commented Sep 28, 2017

Copy link
Copy Markdown
Member Author

However, I'm less sure of the appropriateness of the start-up vs runtime cost trade-off for Counter.most_common, so I'd prefer to see that change in a separate PR.

fixed.

methane merged commit 9811e80 into python:master Sep 30, 2017
methane deleted the bpo31518-functools-import branch September 30, 2017 07:13
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL