classification
Title: Initialize Py_buffer variables more efficiently
Type: performance Stage: patch review
Components: Argument Clinic Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: larry, sir-sigurd
Priority: normal Keywords: patch

Created on 2019-08-13 16:37 by sir-sigurd, last changed 2019-08-13 16:38 by sir-sigurd.

Pull Requests
URL Status Linked Edit
PR 15254 open sir-sigurd, 2019-08-13 16:38
Messages (1)
msg349582 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2019-08-13 16:37
Argument Clinic generates `{NULL, NULL}` initializer for Py_buffer variables. Such initializer zeroes all Py_buffer members, but as I understand only `obj` and `buf` members are really had to be initialized. Avoiding unneeded initialization provides tiny speed-up:

$ python -m perf timeit -s "replace = b''.replace" "replace(b'', b'')" --compare-to=../cpython-master/venv/bin/python --duplicate=1000
/home/sergey/tmp/cpython-master/venv/bin/python: ..................... 43.0 ns +- 0.5 ns
/home/sergey/tmp/cpython-dev/venv/bin/python: ..................... 41.8 ns +- 0.4 ns

Mean +- std dev: [/home/sergey/tmp/cpython-master/venv/bin/python] 43.0 ns +- 0.5 ns -> [/home/sergey/tmp/cpython-dev/venv/bin/python] 41.8 ns +- 0.4 ns: 1.03x faster (-3%)
History
Date User Action Args
2019-08-13 16:38:30sir-sigurdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14975
2019-08-13 16:37:28sir-sigurdcreate