Repository navigation
Commit d4e4427
gh-160858: Use the list freelist in list()
list() allocated its result with PyType_GenericAlloc(), bypassing the
freelist that PyList_New() and the [] display use. For an exact list,
allocate with PyList_New(0) instead. The object handed to
list.__init__() is in the same state either way: empty, with no item
array, and tracked by the GC. Subclasses still use
PyType_GenericAlloc().
pyperf, PGO+LTO, base 19270d3, two interleaved rounds per side
(a third round, disturbed by machine load, was dropped):
| Benchmark | main | branch |
|----------------|:-------:|:---------------------:|
| list() | 21.2 ns | 15.3 ns: 1.38x faster |
| list(d) | 36.1 ns | 27.4 ns: 1.32x faster |
| list(t) | 30.3 ns | 23.9 ns: 1.27x faster |
| list(l) | 32.0 ns | 25.7 ns: 1.24x faster |
| list(r) | 43.6 ns | 36.0 ns: 1.21x faster |
| x + 1 | 10.4 ns | 9.70 ns: 1.07x faster |
| len(l) | 9.87 ns | 9.53 ns: 1.03x faster |
| l[0] | 8.24 ns | 8.00 ns: 1.03x faster |
| L(t) | 48.2 ns | 47.4 ns: 1.02x faster |
| tuple(l) | 15.4 ns | 16.0 ns: 1.04x slower |
| Geometric mean | (ref) | 1.13x faster |
Not significant: []. x + 1, len(l), l[0], L(t) and tuple(l) don't
run the changed code; their movement is layout noise, within the
up-to-1.07x spread between two runs of the same main build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 19270d3 commit d4e4427
2 files changed
Lines changed: 7 additions & 2 deletions
File tree
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3600 | 3600 | | |
3601 | 3601 | | |
3602 | 3602 | | |
3603 | | - | |
| 3603 | + | |
3604 | 3604 | | |
3605 | 3605 | | |
3606 | 3606 | | |
| |||
3632 | 3632 | | |
3633 | 3633 | | |
3634 | 3634 | | |
3635 | | - | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
3636 | 3639 | | |
3637 | 3640 | | |
3638 | 3641 | | |
| |||
0 commit comments