faster-cpython / ideas

1.68k stars 48 forks source link

Improve the usage and implementation of argument clinic. #565

Open markshannon opened 1 year ago

markshannon commented 1 year ago

Let's make better use of argument clinic.

We have a couple of issues/discussions on better interfacing builtin functions and the VM: https://github.com/faster-cpython/ideas/discussions/374 https://github.com/faster-cpython/ideas/issues/546

Which we will want to do, but we need to make argument clinic more widely used and get it produce better code first.

There are two things we can do:

The above two tasks is that they are fully independent in term of implementation, but complement each other nicely in terms of performance improvements. The other nice thing is that they can both be automated.

I've generated stats on the number of calls to the various argument parsing functions in the benchmark suite.

Stats: _PyArg_CheckPositional: 92M calls _PyArg_UnpackKeywords: 44M calls

Compare this to the 9.3 billion bytecode instructions executed. _PyArg_CheckPositional is relatively cheap, which suggests the overhead of these parsing functions is not that big a deal on the benchmark suite, but is still measurable. It could be a lot higher for other code. We will have better numbers when we have automated profiling.