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

Speed hack for function calls with named parameters #46144

Closed
pitrou opened this issue Jan 14, 2008 · 12 comments
Closed

Speed hack for function calls with named parameters #46144

pitrou opened this issue Jan 14, 2008 · 12 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Jan 14, 2008

BPO 1819
Nosy @malemburg, @gvanrossum, @birkenfeld, @rhettinger, @facundobatista, @pitrou, @tiran
Files
  • namedparam.patch
  • namedparam.patch
  • namedparam2.patch
  • namedparam3.patch: Faster, cleaner with PySequence_Fast_ITEMS
  • pybench.patch
  • 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 = 'https://github.com/birkenfeld'
    closed_at = <Date 2008-07-25.22:15:07.764>
    created_at = <Date 2008-01-14.00:48:19.797>
    labels = ['interpreter-core', 'type-feature']
    title = 'Speed hack for function calls with named parameters'
    updated_at = <Date 2008-07-25.22:15:07.763>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2008-07-25.22:15:07.763>
    actor = 'pitrou'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2008-07-25.22:15:07.764>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2008-01-14.00:48:19.797>
    creator = 'pitrou'
    dependencies = []
    files = ['9156', '9157', '10590', '10596', '10600']
    hgrepos = []
    issue_num = 1819
    keywords = ['patch']
    message_count = 12.0
    messages = ['59878', '59879', '59880', '59882', '61556', '68007', '68025', '68026', '68040', '68070', '68092', '70283']
    nosy_count = 7.0
    nosy_names = ['lemburg', 'gvanrossum', 'georg.brandl', 'rhettinger', 'facundobatista', 'pitrou', 'christian.heimes']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1819'
    versions = ['Python 2.6']

    @pitrou
    Copy link
    Member Author

    pitrou commented Jan 14, 2008

    This is a patch for SVN trunk which substantially speeds up function
    calls with named parameters. It does so by taking into account that
    parameter names should be interned, so before doing full compares we do
    a first quick loop to compare pointers.

    On a microbenchmark the speedup is quite distinctive:

    # With patch
    $ ./python -m timeit -s "def f(a,b,c,d,e): pass" "f(1,2,3,4,e=5)"
    1000000 loops, best of 3: 0.515 usec per loop
    $ ./python -m timeit -s "def f(a,b,c,d,e): pass" "f(a=1,b=2,c=3,d=4,e=5)"
    1000000 loops, best of 3: 0.652 usec per loop

    # Without patch
    $ ./python-orig -m timeit -s "def f(a,b,c,d,e): pass" "f(1,2,3,4,e=5)"
    1000000 loops, best of 3: 0.664 usec per loop
    $ ./python-orig -m timeit -s "def f(a,b,c,d,e): pass"
    "f(a=1,b=2,c=3,d=4,e=5)"
    1000000 loops, best of 3: 1.07 usec per loop

    @pitrou pitrou added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jan 14, 2008
    @tiran
    Copy link
    Member

    tiran commented Jan 14, 2008

    Nice! Is this somehow related to bpo-1479611?

    The formatting of the code looks kinda strange. Have you mixed tabs and
    spaces?

    @pitrou
    Copy link
    Member Author

    pitrou commented Jan 14, 2008

    Sorry, my editor indents with spaces by default. Attaching a fixed patch
    with tabs.

    No, it is independent from bpo-1479611 (and much simpler).

    @pitrou
    Copy link
    Member Author

    pitrou commented Jan 14, 2008

    Another quick test:

    # With patch
    $ ./python -m timeit -s "d=dict(a=1,b=2,c=3,d=4,e=5);f = lambda
    a,b,c,d,e:0" "f(**d)"
    1000000 loops, best of 3: 0.727 usec per loop
    $ ./python -m timeit -s "d=dict(b=2,c=3,d=4,e=5);f = lambda a,b,c,d,e:0"
    "f(a=1,**d)"
    1000000 loops, best of 3: 1.16 usec per loop
    $ ./python -m timeit -s "d=dict(b=2,c=3,d=4,e=5); f=lambda **kw:0" "f(**d)"
    1000000 loops, best of 3: 0.917 usec per loop

    # Without patch
    $ ./python-orig -m timeit -s "d=dict(a=1,b=2,c=3,d=4,e=5);f = lambda
    a,b,c,d,e:0" "f(**d)"
    1000000 loops, best of 3: 1.24 usec per loop
    $ ./python-orig -m timeit -s "d=dict(b=2,c=3,d=4,e=5);f = lambda
    a,b,c,d,e:0" "f(a=1,**d)"
    1000000 loops, best of 3: 1.62 usec per loop
    $ ./python-orig -m timeit -s "d=dict(b=2,c=3,d=4,e=5); f=lambda **kw:0"
    "f(**d)"
    1000000 loops, best of 3: 0.904 usec per loop

    @gvanrossum
    Copy link
    Member

    Nice idea, but why set the priority to high? I have no immediate time
    to review this and probably won't for a while.

    @pitrou
    Copy link
    Member Author

    pitrou commented Jun 11, 2008

    Here is a new patch against SVN trunk. Nothing changed, except that I
    updated pybench to test keyword arguments as well.

    @birkenfeld birkenfeld assigned birkenfeld and unassigned gvanrossum Jun 11, 2008
    @malemburg
    Copy link
    Member

    On 2008-06-11 20:38, Antoine Pitrou wrote:

    Antoine Pitrou <pitrou@free.fr> added the comment:

    Here is a new patch against SVN trunk. Nothing changed, except that I
    updated pybench to test keyword arguments as well.

    Added file: http://bugs.python.org/file10590/namedparam2.patch

    When changing parameters or other aspects of pybench tests, you *have*
    to update the version number of the test as well. Otherwise, pybench
    would compare apples with oranges.

    Thanks,

    Marc-Andre Lemburg
    eGenix.com

    Professional Python Services directly from the Source  (#1, Jun 11 2008)
     >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
     >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
     >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
    ________________________________________________________________________
    2008-07-07: EuroPython 2008, Vilnius, Lithuania            25 days to go

    :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
            Registered at Amtsgericht Duesseldorf: HRB 46611
    

    @malemburg
    Copy link
    Member

    On 2008-06-11 23:27, M.-A. Lemburg wrote:

    On 2008-06-11 20:38, Antoine Pitrou wrote:
    > Antoine Pitrou <pitrou@free.fr> added the comment:
    >
    > Here is a new patch against SVN trunk. Nothing changed, except that I
    > updated pybench to test keyword arguments as well.
    >
    > Added file: http://bugs.python.org/file10590/namedparam2.patch

    When changing parameters or other aspects of pybench tests, you *have*
    to update the version number of the test as well. Otherwise, pybench
    would compare apples with oranges.

    BTW: It would probably be better to add a completely new test
    PythonNamedParameterCalls or something along those lines instead
    of changing an existing test.

    @rhettinger
    Copy link
    Contributor

    Attaching a version that's a little faster and cleaner with
    PySequence_Fast_ITEMS.

    @pitrou
    Copy link
    Member Author

    pitrou commented Jun 12, 2008

    And here is a patch adding a new test in pybench as suggested by
    Marc-Andre Lemburg.

    @rhettinger
    Copy link
    Contributor

    Georg, do you want to go ahead and apply this.

    @pitrou
    Copy link
    Member Author

    pitrou commented Jul 25, 2008

    Committed in r65240 (new pybench test) and r65241 (speedup patch).

    @pitrou pitrou closed this as completed Jul 25, 2008
    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants