According to metric in #159702 (comment), NoneType occupied 5%, so it's worth to adding this fast path rather than other type if we have to do.
import pyperf runner = pyperf.Runner() for n in (10, 100, 1000): runner.bench_func(f"repr([None]*{n})", repr, [None] * n)
+-------------------+------------------+-----------------------+ | Benchmark | wr_none_baseline | wr_none_patched | +===================+==================+=======================+ | repr([None]*10) | 559 ns | 234 ns: 2.39x faster | +-------------------+------------------+-----------------------+ | repr([None]*100) | 3.90 us | 1.10 us: 3.53x faster | +-------------------+------------------+-----------------------+ | repr([None]*1000) | 36.9 us | 9.50 us: 3.88x faster | +-------------------+------------------+-----------------------+ | Geometric mean | (ref) | 3.20x faster | +-------------------+------------------+-----------------------+
cc @vstinner @nineteendo
pythongh-159813: Add tests for PyUnicodeWriter_WriteRepr()
gh-159813: Add a fast path for None in PyUnicodeWriter_WriteRepr (gh-…
Activity
corona10 commented on Oct 19, 2026
cc @vstinner @nineteendo
pythongh-159813: Add tests for PyUnicodeWriter_WriteRepr()
gh-159813: Add a fast path for None in PyUnicodeWriter_WriteRepr (gh-…