Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-131586: Avoid refcount contention in some "special" calls#131588

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
colesbury merged 6 commits intopython:mainfromcolesbury:gh-131586-lookup-special
Mar 26, 2025

Conversation

colesbury
Copy link
Contributor

@colesburycolesbury commentedMar 22, 2025
edited by bedevere-appbot
Loading

In the free threaded build, the_PyObject_LookupSpecial() call can lead to reference count contention on the returned function object becuase it doesn't use stackrefs. Refactor some of the callers to use_PyObject_MaybeCallSpecialNoArgs, which uses stackrefs internally.

This fixes the scaling bottleneck in the "lookup_special" microbenchmark inftscalingbench.py. However, the are still some uses of_PyObject_LookupSpecial() that need to be addressed in future PRs.

corona10 reacted with thumbs up emoji
In the free threaded build, the `_PyObject_LookupSpecial()` call can lead toreference count contention on the returned function object becuase itdoesn't use stackrefs. Refactor some of the callers to use`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.This fixes the scaling bottleneck in the "lookup_special" microbenchmarkin `ftscalingbench.py`. However, the are still some uses of`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
if (method != NULL) {
PyObject *result = _PyObject_CallNoArgs(method);
Py_DECREF(method);
PyObject *result = _PyObject_MaybeCallSpecialNoArgs(number, &_Py_ID(__ceil__));
Copy link
Member

Choose a reason for hiding this comment

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

Nice approach, we don't need module state anymore for this case.
cc@vstinner

@colesburycolesbury marked this pull request as ready for reviewMarch 24, 2025 13:31
@colesburycolesbury requested a review frommpageMarch 24, 2025 13:32
@colesburycolesbury added the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelMar 24, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@colesbury for commit93c8143 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F131588%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-refleak-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelMar 24, 2025
Copy link
Contributor

@mpagempage left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 5732 to 5736
/* Internal API to look for a name through the MRO.
This returns a strong reference, and doesn't set an exception!
If nonzero, version is set to the value of type->tp_version at the time of
the lookup.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment needs to be updated.

colesbury reacted with thumbs up emoji
Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

The overall design LGTM and the implementation looks correct. But I don't understand well StackRef, so I prefer to abstain from approving this PR.

Copy link
Member

@markshannonmarkshannon left a comment

Choose a reason for hiding this comment

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

Looks good. One quibble about the naming of a return type.

OOI, do you have any numbers of the impact of the PR, either stats or benchmarks?

@@ -890,6 +890,8 @@ extern bool _PyObject_TryGetInstanceAttribute(PyObject *obj, PyObject *name,
PyObject **attr);
extern PyObject *_PyType_LookupRefAndVersion(PyTypeObject *, PyObject *,
unsigned int *);
extern unsigned int
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
externunsignedint
externuint32_t

int returns imply a very limited range of values, usually only 0/-1. Please use C99 int types when returning actual data, rather just an error code.

Should the comment explaining what it does go here, rather than on the implementation?
It seems to me that "what" comments go in headers, and "how" comments in the C code.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I've moved the comment to the header file. The return value isunsigned int becausetp_version_tag (in PyTypeObject) is anunsigned int and all the other_PyType_Lookup variants store the version tag as anunsigned int.

vstinner reacted with thumbs up emoji
@colesbury

This comment was marked as outdated.

@colesbury

This comment was marked as outdated.

@colesbury
Copy link
ContributorAuthor

Oops... those are the numbers for a different PR (#130064). Performance looks unchanged with this PR (<0.1%)

@colesburycolesbury merged commit67fbfb4 intopython:mainMar 26, 2025
41 checks passed
@colesburycolesbury deleted the gh-131586-lookup-special branchMarch 26, 2025 18:38
@vstinner
Copy link
Member

Nice enhancement.

diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 1, 2025
…ython#131588)In the free threaded build, the `_PyObject_LookupSpecial()` call can lead toreference count contention on the returned function object becuase itdoesn't use stackrefs. Refactor some of the callers to use`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.This fixes the scaling bottleneck in the "lookup_special" microbenchmarkin `ftscalingbench.py`. However, the are still some uses of`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
seehwan pushed a commit to seehwan/cpython that referenced this pull requestApr 16, 2025
…ython#131588)In the free threaded build, the `_PyObject_LookupSpecial()` call can lead toreference count contention on the returned function object becuase itdoesn't use stackrefs. Refactor some of the callers to use`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.This fixes the scaling bottleneck in the "lookup_special" microbenchmarkin `ftscalingbench.py`. However, the are still some uses of`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vstinnervstinnervstinner left review comments

@markshannonmarkshannonmarkshannon left review comments

@mpagempagempage approved these changes

@corona10corona10corona10 approved these changes

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-SpinnerFidget-Spinner is a code owner

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@colesbury@bedevere-bot@vstinner@mpage@corona10@markshannon

[8]ページ先頭

©2009-2025 Movatter.jp