Skip to content

bpo-44525: Specialize for calls to type and other builtin classes with 1 argument. #29942

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

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Dec 6, 2021

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

The code LGTM. Interested to see the benchmark results.

@markshannon
Copy link
Member Author

Benchmark results show a slight speedup, but very close to noise.

I think this is worth including because:

  1. The nbody and spectral norm benchmarks show decent speedups and have range(arg) calls in the hot parts of the benchmark, suggesting that specialization of calls to cls(one_arg) is effective.
  2. Some "real" code includes a lot of type(obj) calls (at least statically).

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

LGTM.

assert(GET_CACHE()->adaptive.original_oparg == 1);
PyObject *obj = TOP();
PyObject *callable = SECOND();
DEOPT_IF(callable != (PyObject *)&PyType_Type, CALL_NO_KW);
Copy link
Member

Choose a reason for hiding this comment

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

I don't remember if you like using the Py_IS_TYPE inline function, but just mentioning it here and leaving it up to you :).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll skip on the obfuscation macro 🙂

return -1;
}
if (nargs == 1) {
if (tp == &PyType_Type) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@markshannon
Copy link
Member Author

Increases CALL_NO_KW hit rate from ~71% to ~74% on the standard benchmark suite, with only a slight increase in the miss rate.
Reduces failed specializations for calls to classes (SPEC_FAIL_CLASS) by over half.

@markshannon markshannon merged commit 3a60bfe into python:main Dec 15, 2021
@markshannon markshannon deleted the specialize-calls-to-builtin-types branch September 26, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants