gh-89013: Improve the performance of methodcaller #106960
Closed
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.
We improve the performance of
methodcaller
by using the vector protocol. The performance improvement depends on the use case, but for simple calls the performance doubles. Creation is a bit slower (because the vector call arguments have to be constructed), but the net gain is positive already after a single invocation of themethodcaller
Benchmark script
Note: this is a continuation of #27782. Changes with respect to that PR
methodcaller_call
was removed in favor of the vector call, but it is still needed for some builds. It is now restored, but less efficientxargs
instead of of a slice to avoid creation of an additional tuplemethodcallerobject
compared to main is now 2 variables PyObject* and a tuple holding the keyword argument names.methodcaller
, one can also defer the construction to the first invocation of themethodcaller
. A branch with this approach is main...eendebakpt:cpython:fastmethodcaller_lazy_vectorcall