FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Adding fastpath for Nonetype in PyUnicodeWriter_WriteRepr · Issue #159813 · python/cpython · GitHub

Repository navigation

Adding fastpath for Nonetype in PyUnicodeWriter_WriteRepr #159813

Closed

Description

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.

Metric

Argument type Calls Share Note
exact int 2,924,088 86.7% existing fast path (_PyLong_FormatWriter)
None 181,066 5.4%  proposed fastpath
exact list 69,501 2.1%  
other types 58,946 1.7% user classes, type objects, etc.
exact str 58,158 1.7%  
exact dict 40,537 1.2%  
bool 20,759 0.6%  
exact float 10,657 0.32%
exact bytes 5,700 0.2%  
exact tuple 2,244 0.07%  
total 3,371,663 100%  

Microbenchmark

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          |
+-------------------+------------------+-----------------------+

Linked PRs

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. corona10 commented on Oct 19, 2026

    MemberAuthor
  3. added a commit that references this issue on Oct 20, 2026
  4. added a commit that references this issue on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL