Skip to content

gh-118932: ChainMap.__contains__ performance improvement #118946

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 1 commit into from
May 11, 2024

Conversation

dg-pb
Copy link
Contributor

@dg-pb dg-pb commented May 11, 2024

Minimal change.

  • Improves ChainMap.__contains__ performance significantly
  • ChainMap.get also benefits from it

@dg-pb dg-pb requested a review from rhettinger as a code owner May 11, 2024 11:41
@ghost
Copy link

ghost commented May 11, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented May 11, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@nineteendo
Copy link
Contributor

nineteendo commented May 11, 2024

Maybe we could even improve the performance of any()? That would be far more useful for users.

@rhettinger rhettinger added performance Performance or resource usage skip news labels May 11, 2024
@rhettinger rhettinger merged commit cd4cfa6 into python:main May 11, 2024
@dg-pb dg-pb deleted the chain_map_contains_optim branch May 11, 2024 22:33
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
bdraco added a commit to home-assistant/core that referenced this pull request Aug 3, 2024
On slower systems, there is a noticable stall right after startup
when all the discoveries hit if there are a lot of discoveries.
While we have imporved this by avoding imports in the event loop,
this is still apparent on slower systems. The any expressions kept
coming up in the profile, but I had skipped over them, as I was
thinking they could not be optimized. After reading
python/cpython#118932, I realized
its the any expressions themselves that perform poorly.

This change unpacks the hot any expressions with the same
solution as python/cpython#118946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants