Repository navigation
Conversation
📖 51 files modified
Preview · build overview · cpython-previews · built Dec. 4, 2026, 6:32 p.m. UTC |
|
I ran a benchmark on Fedora 45 with CPU isolation and Python built with Free Threading: The benchmark only create set objects. See #160154 (comment) for benchmarks on frozenset objects. Benchmark files: Results all together:
Columns:
Compare
Compare
Compare
|
Use the new API in: * Modules/_abc.c * Modules/_asynciomodule.c * Modules/_hashopenssl.c * Modules/_ssl.c
PySetBuilder C APIPySetBuilder C API
Unrelated failure. A FTP test of test_urllib2net failed with "425 Security: Bad IP connecting":
|
| { | ||
| int ret = -1; | ||
| PyObject *abstracts = PyFrozenSet_New(NULL); | ||
| PySetBuilder *abstracts = PySetBuilder_CreateFrozenSet(0); |
There was a problem hiding this comment.
I honestly don't like the naming PySetBuilder_CreateFrozenSet but I don't have anything better to suggest. It's... a bit weird to have the combination of a builder and "create" at the same time. Maybe PySetBuilder_ForFrozenSet though PySetBuilder_ForSet is really weird as well.
If you plan to have more builder APIs such as PyFastSequenceBuilder_CreateList()/CreateTuple, feel free to ignore this comment though.
|
The API is being discussed at capi-workgroup/decisions#119. |
Move PySet_MINSIZE constant at the module level
If set_add_entry_takeref() fails, Py_DECREF(item) must not be called.
ASSERT_CAN_MODIFY_SET() now uses Py_REFCNT()==1 instead of checking _PyObject_IsUniquelyReferenced().
|
My preference (which I know doesn't count for much) is to not expand the C-API unless we have to. Unless we expectmostl future C code to be created by AI, we should respect that humans have a much smaller context window. The current The builder API is more complex. Aside from minute timing differences, the proposal seems gratuitous. |
This PR is based on PR gh-160154. It renames
PyFrozenSetWritertoPyFrozenSetBuilder, and adds the ability to also create set objects, not only frozenset objects.Use the new API in:
When building a set, PySet_Add() suffers from the same performance issue than PyList_Add() on Free Threading (issue gh-158660): each call needs a critical section.
PyFrozenWriterC API to create afrozensetobject #160147