GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-31581: Reduce the number of imports for functools by methane · Pull Request #3757 · python/cpython

Conversation

@methane

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

Uh oh!

There was an error while loading. Please reload this page.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@methane
methane requested review from ncoghlan and rhettinger as code owners September 26, 2017 03:55
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Sep 26, 2017
@bedevere-bot bedevere-bot added the awaiting merge label Sep 26, 2017
@methane methane added the skip news label Sep 26, 2017
@methane

methane commented Sep 26, 2017

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan
ncoghlan previously requested changes Sep 26, 2017
View reviewed changes

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot

bedevere-bot commented Sep 26, 2017

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting changes and removed awaiting merge labels Sep 26, 2017
methane added 2 commits September 26, 2017 17:19
@methane
Reduce the number of imports for functools
d648fc8
@methane
Revert collections module
f228a84
@methane
methane force-pushed the bpo31518-functools-import branch from a0082b6 to f228a84 Compare September 26, 2017 08:47
methane added 2 commits September 26, 2017 17:51
@methane
Add comment about lazy import
cac0c73
@methane
Fix TestSingleDispatch
865f333
serhiy-storchaka
serhiy-storchaka reviewed Sep 26, 2017
View reviewed changes
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

@serhiy-storchaka serhiy-storchaka Sep 26, 2017

Copy link
Copy Markdown
Member

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

@serhiy-storchaka serhiy-storchaka Sep 26, 2017

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
methane added 2 commits September 27, 2017 18:16
@methane
Use import instead of from ... import
fd86dde
@methane
Use support.swap_attr in TestSingleDispatch
26b0b32
@methane

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@methane
Add import comment at top of the module.
99eeeb9
ref: https://bugs.python.org/issue31581#msg303366
@methane
methane dismissed ncoghlan’s stale review September 30, 2017 06:57

fixed

@methane
methane merged commit 9811e80 into python:master Sep 30, 2017
@methane
methane deleted the bpo31518-functools-import branch September 30, 2017 07:13
@Mariatta Mariatta removed the awaiting changes label Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@ncoghlan ncoghlan ncoghlan left review comments
@rhettinger rhettinger Awaiting requested review from rhettinger

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@methane @bedevere-bot @ncoghlan @serhiy-storchaka @Mariatta @the-knights-who-say-ni
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.