Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Oct 9, 2024

PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call directly _PyLong_FormatWriter() if the object is an int.

PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call
directly _PyLong_FormatWriter() if the object is an int.
@vstinner
Copy link
Member Author

vstinner commented Oct 9, 2024

Benchmark using PR gh-125202 as reference:

import pyperf
runner = pyperf.Runner()

runner.bench_func('repr([1,2,3])', repr, [1, 2, 3])
list2 = [123]*10
runner.bench_func('repr(list2)', repr, list2)
list3 = [123]*50
runner.bench_func('repr(list3)', repr, list3)

Comparison without / with this change:

+----------------+---------+-----------------------+
| Benchmark      | ref     | change                |
+================+=========+=======================+
| repr([1,2,3])  | 291 ns  | 189 ns: 1.54x faster  |
+----------------+---------+-----------------------+
| repr(list2)    | 822 ns  | 498 ns: 1.65x faster  |
+----------------+---------+-----------------------+
| repr(list3)    | 3.01 us | 1.56 us: 1.93x faster |
+----------------+---------+-----------------------+
| Geometric mean | (ref)   | 1.70x faster          |
+----------------+---------+-----------------------+

@vstinner vstinner merged commit ee3167b into python:main Oct 9, 2024
37 checks passed
@vstinner vstinner deleted the writer_specialize branch October 9, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant