Skip to content

bpo-37348: optimize decoding ASCII string#14283

Merged
methane merged 7 commits intopython:masterfrom
methane:ascii-fromstring
Jun 24, 2019
Merged

bpo-37348: optimize decoding ASCII string#14283
methane merged 7 commits intopython:masterfrom
methane:ascii-fromstring

Conversation

@methane
Copy link
Copy Markdown
Member

@methane methane commented Jun 21, 2019

Use _PyUnicode_Writer only after ascii_decode is failed.

https://bugs.python.org/issue37348

@brettcannon brettcannon added the performance Performance or resource usage label Jun 21, 2019
Comment thread Objects/unicodeobject.c Outdated
@methane
Copy link
Copy Markdown
Member Author

methane commented Jun 22, 2019

$ ./python -m pyperf timeit --compare-to=./python-master -s 'b=b"foo"' -- 'b.decode()'
python-master: ..................... 83.3 ns +- 1.2 ns
python: ..................... 72.4 ns +- 1.1 ns

Mean +- std dev: [python-master] 83.3 ns +- 1.2 ns -> [python] 72.4 ns +- 1.1 ns: 1.15x faster (-13%)

PyUnicode_FromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");: about 38ns -> 28ns

@methane methane merged commit 770847a into python:master Jun 24, 2019
@methane methane deleted the ascii-fromstring branch June 24, 2019 03:30
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
`_PyUnicode_Writer` is a relatively complex structure.  Initializing it is significant overhead when decoding short ASCII string.
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
`_PyUnicode_Writer` is a relatively complex structure.  Initializing it is significant overhead when decoding short ASCII string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants