classification
Title: Convert str(), bytes() and bytearray() to Argument Clinic
Type: performance Stage: resolved
Components: Argument Clinic, Installation, Unicode Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, larry, serhiy.storchaka, vstinner, xtreak
Priority: normal Keywords: patch

Created on 2020-07-18 14:58 by serhiy.storchaka, last changed 2020-07-20 12:56 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21535 merged serhiy.storchaka, 2020-07-18 15:04
Messages (2)
msg373906 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-18 14:58
Constructors str(), bytes() and bytearray() were not converted to Argument Clinic because it was not possible to generate correct signature for them. But now there is other reason of using Argument Clinic -- it generates more efficient code for parsing arguments.

The proposed PR converts str(), bytes() and bytearray() to Argument Clinic but generated docstrings are not used.

$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str()"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 81.9 ns +- 4.5 ns -> [/home/serhiy/py/cpython-release/python] 60.0 ns +- 1.9 ns: 1.36x faster (-27%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str('abcdefgh')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 121 ns +- 3 ns -> [/home/serhiy/py/cpython-release/python] 87.6 ns +- 2.8 ns: 1.38x faster (-28%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(12345)"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 188 ns +- 8 ns -> [/home/serhiy/py/cpython-release/python] 149 ns +- 5 ns: 1.27x faster (-21%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', 'ascii')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 210 ns +- 7 ns -> [/home/serhiy/py/cpython-release/python] 164 ns +- 6 ns: 1.28x faster (-22%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', 'ascii', 'strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 222 ns +- 9 ns -> [/home/serhiy/py/cpython-release/python] 170 ns +- 6 ns: 1.30x faster (-23%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', encoding='ascii', errors='strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 488 ns +- 20 ns -> [/home/serhiy/py/cpython-release/python] 306 ns +- 5 ns: 1.59x faster (-37%)

$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes()"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 85.1 ns +- 2.2 ns -> [/home/serhiy/py/cpython-release/python] 60.2 ns +- 2.3 ns: 1.41x faster (-29%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes(8)"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 160 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 115 ns +- 4 ns: 1.39x faster (-28%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes(b'abcdefgh')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 131 ns +- 6 ns -> [/home/serhiy/py/cpython-release/python] 91.0 ns +- 2.8 ns: 1.43x faster (-30%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', 'ascii')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 190 ns +- 6 ns -> [/home/serhiy/py/cpython-release/python] 144 ns +- 5 ns: 1.32x faster (-24%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', 'ascii', 'strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 214 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 156 ns +- 4 ns: 1.37x faster (-27%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', encoding='ascii', errors='strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 442 ns +- 9 ns -> [/home/serhiy/py/cpython-release/python] 269 ns +- 8 ns: 1.64x faster (-39%)

$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray()"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 93.5 ns +- 2.1 ns -> [/home/serhiy/py/cpython-release/python] 73.1 ns +- 1.8 ns: 1.28x faster (-22%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray(8)"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 154 ns +- 3 ns -> [/home/serhiy/py/cpython-release/python] 117 ns +- 3 ns: 1.32x faster (-24%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray(b'abcdefgh')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 164 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 131 ns +- 2 ns: 1.25x faster (-20%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', 'ascii')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 239 ns +- 7 ns -> [/home/serhiy/py/cpython-release/python] 193 ns +- 4 ns: 1.24x faster (-19%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', 'ascii', 'strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 260 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 207 ns +- 10 ns: 1.26x faster (-21%)
$ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', encoding='ascii', errors='strict')"
Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 505 ns +- 11 ns -> [/home/serhiy/py/cpython-release/python] 322 ns +- 7 ns: 1.57x faster (-36%)
msg374003 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-20 12:53
New changeset 12f433411bba8a0cdc4f09ba34472745ae9da0d1 by Serhiy Storchaka in branch 'master':
bpo-41334: Convert constructors of str, bytes and bytearray to Argument Clinic (GH-21535)
https://github.com/python/cpython/commit/12f433411bba8a0cdc4f09ba34472745ae9da0d1
History
Date User Action Args
2020-07-20 12:56:38serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-07-20 12:53:59serhiy.storchakasetmessages: + msg374003
2020-07-18 15:06:12xtreaksetnosy: + xtreak
2020-07-18 15:04:33serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request20673
2020-07-18 14:58:51serhiy.storchakacreate