This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use _PyBytesWriter for unicode escape and raw unicode escape encoders
Type: performance Stage:
Components: Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2015-10-09 12:13 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
unicode_escape.patch vstinner, 2015-10-09 12:13 review
Messages (4)
msg252599 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-10-09 12:13
Attached patch modifies unicode escape and raw unicode escape encoders to use the new _PyBytesWriter API.

The patch is optimized to encode Latin1 characters: encoding Latin1 characters when no character is escaped should not have to call _PyByte_Resize() at all.

When characters are escaped or a BMP or non-BMP string is encoded, overallocation is used to reduce the number of _PyByte_Resize(). It uses _PyBytesWriter overallocation strategy instead of always overallocate for the worst case.

_PyBytesWriter also embeds a small buffer allocated on the stack which also avoids calls to _PyBytes_Resize() when the output fits into 512 bytes.
msg252600 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-10-09 12:15
A few more encoders should be updated to use _PyBytesWriter API:

* Code Page (Windows only)
* Charmap
* UTF-7
* UTF-16
* UTF-32
msg252601 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-10-09 12:16
The _PyBytesWriter API was added in the issue #25318. See also the issue #25349 which optimized bytes % args.
msg252888 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-10-12 20:39
New changeset 8e27f8398a4f by Victor Stinner in branch 'default':
Issue #25353: Optimize unicode escape and raw unicode escape encoders to use
https://hg.python.org/cpython/rev/8e27f8398a4f
History
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69540
2015-10-12 20:41:38vstinnersetstatus: open -> closed
resolution: fixed
2015-10-12 20:39:28python-devsetnosy: + python-dev
messages: + msg252888
2015-10-09 12:16:37vstinnersetmessages: + msg252601
2015-10-09 12:15:27vstinnersetmessages: + msg252600
2015-10-09 12:13:42vstinnercreate