← 输入框|github.com|刷新
Skip to content

gh-87613: Use AC and AC vectorcall for bool - #160791

Open
cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:ac_vc_bool
Open

cmaloney wants to merge 1 commit into
python:mainfrom
cmaloney:ac_vc_bool

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Move bool.__new__ to Argument Clinic with @vectorcall, dropping the hand-written bool_new and bool_vectorcall. The generated vectorcall name matches the hand-written one so the tp_vectorcall slot is unchanged, and argument error messages are unchanged on both paths.

pyperf microbenchmark (PGO+LTO, run serially), no significant change on the vectorcall path:

Benchmark base bool
bool.__new__ 23.0 ns 21.7 ns: 1.06x faster
bool() 10.1 ns 10.4 ns: 1.03x slower
bool(int) 12.2 ns 12.6 ns: 1.03x slower
bool(True) 11.1 ns 11.4 ns: 1.03x slower
Geometric mean (ref) 1.00x slower

Benchmark hidden because not significant (2): bool(bool), bool(list)

Instructions per call (callgrind, inclusive of bool_vectorcall or bool_new, PGO+LTO):

Case base bool delta
bool() 17 18 +1
bool(True) 20 23 +3
bool(12345) 53 49 -4
bool([1]) 50 47 -3
bool.__new__(bool, 1) 127 69 -58

Move bool.__new__ to Argument Clinic with @vectorcall, dropping the
hand-written bool_new and bool_vectorcall. The generated vectorcall name
matches the hand-written one so the tp_vectorcall slot is unchanged, and
argument error messages are unchanged on both paths.

pyperf microbenchmark (PGO+LTO, run serially), no significant change on
the vectorcall path:

| Benchmark      | base    | bool                  |
|----------------|:-------:|:---------------------:|
| bool.__new__   | 23.0 ns | 21.7 ns: 1.06x faster |
| bool()         | 10.1 ns | 10.4 ns: 1.03x slower |
| bool(int)      | 12.2 ns | 12.6 ns: 1.03x slower |
| bool(True)     | 11.1 ns | 11.4 ns: 1.03x slower |
| Geometric mean | (ref)   | 1.00x slower          |

Benchmark hidden because not significant (2): bool(__bool__), bool(list)

Instructions per call (callgrind, inclusive of bool_vectorcall or
bool_new, PGO+LTO):

| Case                  | base | bool | delta |
|-----------------------|-----:|-----:|------:|
| bool()                |   17 |   18 |    +1 |
| bool(True)            |   20 |   23 |    +3 |
| bool(12345)           |   53 |   49 |    -4 |
| bool([1])             |   50 |   47 |    -3 |
| bool.__new__(bool, 1) |  127 |   69 |   -58 |

The compiler folds PyObject_IsTrue(Py_False) for bool(), so the default
costs nothing; the small deltas are register allocation. bool.__new__
drops PyArg_UnpackTuple for inline clinic parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Oct 28, 2026
@cmaloney cmaloney changed the title gh-87613: Use AC vectorcall for bool gh-87613: Use AC and AC vectorcall for bool Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant