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 — gh-132657: optimize `PySet_Contains` for `frozensets` by kumaraditya303 · Pull Request #141183 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Nov 7, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Avoid taking critical section if the object is an exact frozenset.

  • Issue: copy.copy and copy.deepcopy scale poorly with free-threading #132657

Sorry, something went wrong.

Uh oh!

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

All reactions
@kumaraditya303
optimize PySet_Contains for frozensets
e32adeb
@kumaraditya303
kumaraditya303 requested a review from rhettinger as a code owner November 7, 2025 10:11
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 7, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 7, 2025
copy.copy and copy.deepcopy scale poorly with free-threading #132657
Closed
@kumaraditya303 kumaraditya303 added skip news topic-free-threading labels Nov 7, 2025
Carreau
Carreau reviewed Nov 7, 2025
View reviewed changes
Comment thread Objects/setobject.c Resolved

Uh oh!

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

eendebakpt
eendebakpt approved these changes Nov 7, 2025
View reviewed changes

@eendebakpt eendebakpt 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.

Looks good to me. Also see #132290, which also removes locks for set arguments to PySet_Contains.

Sorry, something went wrong.

Uh oh!

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

All reactions
@kumaraditya303
code review
f550bb5
@kumaraditya303
kumaraditya303 force-pushed the set-optimize branch from 1e148e1 to f550bb5 Compare November 7, 2025 12:44
@Carreau

Carreau commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Do you want to include a variation of my proposed test in testcapi/set.c ? With the proper Null checks and Pydecref of course. This will avoid regressions.

All reactions

Sorry, something went wrong.

Uh oh!

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

Carreau
Carreau approved these changes Nov 7, 2025
View reviewed changes
@kumaraditya303

kumaraditya303 commented Nov 11, 2025

Copy link
Copy Markdown
Contributor Author

Do you want to include a variation of my proposed test in testcapi/set.c ? With the proper Null checks and Pydecref of course. This will avoid regressions.

Would you like to propose a PR for that? That could be backported as well but since this PR is perf optimization it won't be backported.

Carreau reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@kumaraditya303
kumaraditya303 merged commit 7211a34 into python:main Nov 11, 2025
44 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting core review label Nov 11, 2025
@kumaraditya303
kumaraditya303 deleted the set-optimize branch November 11, 2025 14:32
Carreau pushed a commit to Carreau/cpython that referenced this pull request Nov 11, 2025
User
Add regression test for PySet_Contains
c518806
As discussed in pythongh-141183, the test suite did not
test that PySet_Contains does not convert unhashable key
into a frozenset.

This commit adds a regression test for this
behavior, to ensure that any behavior change is
caught by the test suite.
Carreau added a commit to Carreau/cpython that referenced this pull request Nov 11, 2025
@Carreau User
Add regression test for PySet_Contains
24b39e7
As discussed in pythongh-141183, the test suite did not
test that PySet_Contains does not convert unhashable key
into a frozenset.

This commit adds a regression test for this
behavior, to ensure that any behavior change is
caught by the test suite.
Carreau added a commit to Carreau/cpython that referenced this pull request Nov 11, 2025
@Carreau
Add regression test for PySet_Contains
a9af13f
As discussed in pythongh-141183, the test suite did not
test that PySet_Contains does not convert unhashable key
into a frozenset.

This commit adds a regression test for this
behavior, to ensure that any behavior change is
caught by the test suite.
@Carreau Carreau mentioned this pull request Nov 11, 2025
gh-132657: Add regression test for PySet_Contains #141411
Merged
@Carreau

Carreau commented Nov 11, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Done as #141411

All reactions

Sorry, something went wrong.

Uh oh!

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

Carreau added a commit to Carreau/cpython that referenced this pull request Nov 11, 2025
@Carreau
Add regression test for PySet_Contains
9d02192
As discussed in pythongh-141183, the test suite did not
test that PySet_Contains does not convert unhashable key
into a frozenset.

This commit adds a regression test for this
behavior, to ensure that any behavior change is
caught by the test suite.
@nascheme nascheme added the needs backport to 3.14 bugs and security fixes label Nov 19, 2025
@miss-islington-app

miss-islington-app Bot commented Nov 19, 2025

Copy link
Copy Markdown

Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 19, 2025
@kumaraditya303 @miss-islington
pythongh-132657: optimize PySet_Contains for frozenset (pythonGH-…
9d1cfc1
…141183)

(cherry picked from commit 7211a34)

Co-authored-by: Kumar Aditya <[email protected]>
@bedevere-app

bedevere-app Bot commented Nov 19, 2025

Copy link
Copy Markdown

GH-141773 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 19, 2025
nascheme pushed a commit that referenced this pull request Nov 20, 2025
@miss-islington @kumaraditya303
[3.14] gh-132657: optimize PySet_Contains for frozenset (GH-141183)…
072eeaf
… (gh-141773)

(cherry picked from commit 7211a34)

Co-authored-by: Kumar Aditya <[email protected]>
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@kumaraditya303 @StanFromIreland
pythongh-132657: optimize PySet_Contains for frozenset (python#14…
0049b04
…1183)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eendebakpt eendebakpt eendebakpt approved these changes
@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner
+1 more reviewer
@Carreau Carreau Carreau approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

skip news topic-free-threading

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.

4 participants

@kumaraditya303 @Carreau @eendebakpt @nascheme
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 01402520 — 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.