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: micro-optimizations in functools.reduce()
Type: performance Stage: resolved
Components: Extension Modules Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, sir-sigurd, xtreak
Priority: normal Keywords: patch

Created on 2018-08-01 05:09 by sir-sigurd, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8598 merged sir-sigurd, 2018-08-01 05:10
Messages (2)
msg322841 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2018-08-01 05:09
`PyTuple_SetItem()` can be replaced with macro version and `PyObject_Call()` can be used instead of `PyEval_CallObject()`.

Here's benchmark results:

$ python -m perf timeit --compare-to ~/tmp/cpython-master-venv/bin/python -s "from functools import reduce; from operator import is_; r = range(50000)" "reduce(is_, r)"
/home/sergey/tmp/cpython-master-venv/bin/python: ..................... 1.64 ms +- 0.01 ms
/home/sergey/tmp/cpython-venv/bin/python: ..................... 1.40 ms +- 0.00 ms

Mean +- std dev: [/home/sergey/tmp/cpython-master-venv/bin/python] 1.64 ms +- 0.01 ms -> [/home/sergey/tmp/cpython-venv/bin/python] 1.40 ms +- 0.00 ms: 1.17x faster (-15%)
msg344222 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-06-01 20:32
New changeset e5f6207ba6cb510d9370519ba869296be01787be by Raymond Hettinger (Sergey Fedoseev) in branch 'master':
bpo-34303: Micro-optimizations in functools.reduce() (GH-8598)
https://github.com/python/cpython/commit/e5f6207ba6cb510d9370519ba869296be01787be
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78484
2019-06-01 20:32:46rhettingersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-06-01 20:32:21rhettingersetnosy: + rhettinger
messages: + msg344222
2018-08-01 09:12:25methanesettype: enhancement -> performance
versions: + Python 3.8
2018-08-01 08:27:28xtreaksetnosy: + xtreak
2018-08-01 05:10:27sir-sigurdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8107
2018-08-01 05:09:03sir-sigurdcreate