]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-119396: Optimize unicode_repr() (#119617)
authorVictor Stinner <vstinner@python.org>
Tue, 28 May 2024 16:05:20 +0000 (18:05 +0200)
committerGitHub <noreply@github.com>
Tue, 28 May 2024 16:05:20 +0000 (18:05 +0200)
commit0518edc17049a2f474b049b7d7fe3ef4339ceb83
tree19d3112f06d2466cac1751e4109c9f551d81709f
parent2da0dc094fa855ed4df251aab58b6f8a2b6969a1
gh-119396: Optimize unicode_repr() (#119617)

Use stringlib to specialize unicode_repr() for each string kind
(UCS1, UCS2, UCS4).

Benchmark:

+-------------------------------------+---------+----------------------+
| Benchmark                           | ref     | change2              |
+=====================================+=========+======================+
| repr('abc')                         | 100 ns  | 103 ns: 1.02x slower |
+-------------------------------------+---------+----------------------+
| repr('a' * 100)                     | 369 ns  | 369 ns: 1.00x slower |
+-------------------------------------+---------+----------------------+
| repr(('a' + squote) * 100)          | 1.21 us | 946 ns: 1.27x faster |
+-------------------------------------+---------+----------------------+
| repr(('a' + nl) * 100)              | 1.23 us | 907 ns: 1.36x faster |
+-------------------------------------+---------+----------------------+
| repr(dquote + ('a' + squote) * 100) | 1.08 us | 858 ns: 1.25x faster |
+-------------------------------------+---------+----------------------+
| Geometric mean                      | (ref)   | 1.16x faster         |
+-------------------------------------+---------+----------------------+
Makefile.pre.in
Objects/stringlib/repr.h [new file with mode: 0644]
Objects/unicodeobject.c
Tools/c-analyzer/cpython/_parser.py