{{ message }}
gh-127065: Make methodcaller thread-safe and re-entrant#127245
Closed
eendebakpt wants to merge 21 commits into
Closed
gh-127065: Make methodcaller thread-safe and re-entrant#127245eendebakpt wants to merge 21 commits into
eendebakpt wants to merge 21 commits into
Conversation
colesbury
reviewed
Nov 25, 2024
colesbury
left a comment
Contributor
There was a problem hiding this comment.
A few comments:
- I don't think
_methodcaller_initialize_vectorcallis thread safe without the GIL. Lazily initializing arguments complicates the code and thread-safety -- I don't think it's worth it. - Generally, I think it's better to support some fixed max number of arguments (like 8), and stack allocate the temporary array. (i.e.,
PyObject **tmp_args[MAX_ARGS];). If themethodcallerneeds more arguments than that, just don't set thevectorcallfield and let it fall back to thetp_call.
Sorry, something went wrong.
colesbury
reviewed
Dec 2, 2024
colesbury
reviewed
Dec 3, 2024
colesbury
left a comment
Contributor
There was a problem hiding this comment.
Overall this looks good to me. A few minor formatting suggestions below.
Sorry, something went wrong.
Co-authored-by: Sam Gross <colesbury@gmail.com>
Co-authored-by: Sam Gross <colesbury@gmail.com>
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
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.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.
The function
operator.methodcalleris not thread-safe since the additional of the vectorcall method in ##107201. In the free-threading build the issue is easy to trigger, for the normal build harder.We could either remove the vectorcall implementation, or adapt the vectorcall implementation to be thread safe (for both the normal and free-threading build). In this PR we make the
methodcallersafe bytp_callfor more than 8 argumentsBenchmark results:
(old machine, no PGO, comparing this PR with the same PR but the vectorcall disabled)
Benchmark script
methodcalleris not thread-safe (or re-entrant) #127065