Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micro-optimizations in functools.reduce() #78484

Closed
sir-sigurd mannequin opened this issue Aug 1, 2018 · 2 comments
Closed

micro-optimizations in functools.reduce() #78484

sir-sigurd mannequin opened this issue Aug 1, 2018 · 2 comments
Labels
3.8 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@sir-sigurd
Copy link
Mannequin

sir-sigurd mannequin commented Aug 1, 2018

BPO 34303
Nosy @rhettinger, @sir-sigurd, @tirkarthi
PRs
  • bpo-34303: Micro-optimizations in functools.reduce() #8598
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-06-01.20:32:46.131>
    created_at = <Date 2018-08-01.05:09:03.896>
    labels = ['extension-modules', '3.8', 'performance']
    title = 'micro-optimizations in functools.reduce()'
    updated_at = <Date 2019-06-01.20:32:46.130>
    user = 'https://github.com/sir-sigurd'

    bugs.python.org fields:

    activity = <Date 2019-06-01.20:32:46.130>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-01.20:32:46.131>
    closer = 'rhettinger'
    components = ['Extension Modules']
    creation = <Date 2018-08-01.05:09:03.896>
    creator = 'sir-sigurd'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34303
    keywords = ['patch']
    message_count = 2.0
    messages = ['322841', '344222']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'sir-sigurd', 'xtreak']
    pr_nums = ['8598']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue34303'
    versions = ['Python 3.8']

    @sir-sigurd
    Copy link
    Mannequin Author

    sir-sigurd mannequin commented Aug 1, 2018

    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%)

    @sir-sigurd sir-sigurd mannequin added type-feature A feature request or enhancement extension-modules C modules in the Modules dir labels Aug 1, 2018
    @methane methane added 3.8 only security fixes performance Performance or resource usage and removed type-feature A feature request or enhancement labels Aug 1, 2018
    @rhettinger
    Copy link
    Contributor

    New changeset e5f6207 by Raymond Hettinger (Sergey Fedoseev) in branch 'master':
    bpo-34303: Micro-optimizations in functools.reduce() (GH-8598)
    e5f6207

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants