-
-
Notifications
You must be signed in to change notification settings - Fork 52
c api next level manifesto
Python's C extension API has historically been one of it's strengths. A huge ecosystem of high-performance scientific and numerical software has been built on top of it. It got us this far, but now it's holding us back. It's time to take it to the next level.
The existing C API exposes many details of how Python was implemented. This prevents both the evolution of the current Python implementation and the successful creation of new implementations.
In particular, the existing C API exposes the implementation of a Python objects rather than the semantics of a Python object.
In order to avoid exposing the details of the Python implementation, the next level API should:
- Not return borrowed references.
- Not steal references.
- Not expose reference counting as part of the API.
- Not expose the location of objects in memory.
- Not rely on pointers for object identity.
- Not expose the memory layout of Python objects as part of the API.
- Not expose static types.
- Expose Python (the language), not a specific Python implementation version.
- Expose constructs generally useful in C, not constructs specific to a Python implementation version.
- Provide an explicit execution context.
There are also many good things about the existing API and we don't want to change everything. The next level API should be a subset of the existing API as far as the changes above allow.
For a more detailed explanation of what needs to change, see What needs to change and why.
- The existing ecosystem of C extensions should continue to work.
- Performance of existing C extensions run on CPython should be no worse.
- There should be a sensible migration path for big C extensions (e.g. numpy).
- There should be a way to easily pick up common errors introduced by migrating.
In short, we should avoid making the lives of maintainers and users of C extensions difficult.
If everything above is achievable -- and we believe it is! -- we'll arrive in a wonderful new future where Python implementations can experiment with all sorts of amazing new features:
- tracing garbage collectors
- nurseries for short-lived objects
- sub-interpreters with separate contexts
- specialised implementations of lists
- removing the GIL
- avoiding the boxing of primitive types
- just-in-time compilation
... and many other things you can imagine that we haven't!
No one can guarantee that a particular new idea will work out, but exposing fewer implementation details via the C API will make it possible to try many new things.
Excitingly, we believe all of these changes are achievable within the constraints. We're currently working on one way to achieve them and we'd love input and feedback and welcome contributions of all kinds!
- 5 September 2024
- 4 April 2024
- 7 March 2024
- 1 February 2024
- 11 January 2024
- 7 December 2023
- 9 November 2023
- 5 October 2023
- 14 September 2023
- 3 August 2023
- 6 July 2023
- 1 June 2023
- 4 May 2023
- 13 April 2023
- 2 March 2023
- 2 February 2023
- 12 January 2023
- 1 December 2022
- 3 November 2022
- 6 October 2022
- 8 September 2022
- 4 August 2022
- 7 July 2022
- 2 June 2022
- 5 May 2022
- 7 April 2022
- 3 March 2022
- 3 February 2022
- 13 January 2022
- 2 December 2021
- 4 November 2021
- 7 October 2021
- 2 September 2021
- 12 August 2021
- 8 July 2021
- 6 May 2021
- 4 March 2021
- 7 January 2021
- 3 December 2020
- 5 November 2020