[Exploration] Specialize list storage for integers, floats, and booleans
A list keeps one heap identity while its storage adapts to the values it holds.
| Contents | Storage |
|---|---|
| Integers from 0 through 255 | One byte per element |
| Other immediate integers | Signed 64-bit slots |
| Floats | 64-bit float slots, preserving signed zero and NaN payloads |
| Booleans | One bit per element |
Only None | A length and a reserved bitmap counted against the memory budget |
| Mixed types or arbitrary-precision integers | Generic Value slots |
Integer, float, and boolean lists can also hold None using a separate one-bit-per-element bitmap. An integer outside the byte range widens the buffer before replacing it. A drained list can reuse its capacity for compatible values or switch storage on refill. Dumps store the logical values in field I and the heap-reference flag in C. A regression test compares the CBOR bytes from each packed strategy with the pre-PR list encoding and checks that each reader accepts the other writer’s bytes. Nonempty lists restore into generic storage. The current dump version is 16 and the oldest supported version is 13.
Integer subscripts read the storage directly. Compatible numeric slice assignments snapshot the right-hand side in typed slots, including self-assignment. Lists constructed from bytes and ranges fill packed buffers directly. The benchmark suite covers reads, writes, copies, construction, and slicing across storage types.
Float measurements
Local release builds before and after adding float storage. Each timing is the median of three run medians, with 25 measured executions per run.
| Workload | Generic float list | Packed float list |
|---|---|---|
| Payload for one million floats | 16 MB | 8 MB |
| Build a 200,000-float list, then copy and slice it 16 times | 6.77 ms | 0.75 ms |
| Read 65,536 indexed floats | 1.35 ms | 1.36 ms |
Earlier byte-storage measurements
These figures compare the original byte-storage commit with the same rebased tree using packed 64-bit integers. Each number is the median of six alternating runs on Apple Silicon.
| Workload | Packed 64-bit integers | With byte storage |
|---|---|---|
| Retained bytes for a one-million-item list | 8.00 MB | 1.00 MB |
list(bytes_data) for one million bytes | 7.520 ms | 0.018 ms |
| Copy the resulting list | 0.151 ms | 0.019 ms |
| Write 256 into the resulting list | 0.002 ms | 0.095 ms |
| Fannkuch | 0.635 ms | 0.641 ms |
| Float workload | 3.741 ms | 3.774 ms |
| CSV writing | 5.204 ms | 5.192 ms |
Local verification passed 1,218 interpreter tests with memory-model checks, 1,592 Python fixture runs across Monty and CPython, and 123 subprocess tests. The worker tests cover one million nullable floats under a 10 MiB limit and verify that a refused promotion preserves the list. Clippy passed for the interpreter and runtime test targets.