Skip to content

Modify PyObject_CallFunction() to use fast call internally #73101

Closed

Description

@vstinner
BPO 28915
Nosy @vstinner
Files
  • bench_slots.py
  • 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 2016-12-09.16:28:57.063>
    created_at = <Date 2016-12-09.01:07:34.083>
    labels = ['3.7', 'performance']
    title = 'Modify PyObject_CallFunction() to use fast call internally'
    updated_at = <Date 2016-12-27.15:59:28.462>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2016-12-27.15:59:28.462>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-12-09.16:28:57.063>
    closer = 'vstinner'
    components = []
    creation = <Date 2016-12-09.01:07:34.083>
    creator = 'vstinner'
    dependencies = []
    files = ['45808']
    hgrepos = []
    issue_num = 28915
    keywords = []
    message_count = 8.0
    messages = ['282748', '282749', '282751', '282780', '282786', '282789', '283286', '284109']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue28915'
    versions = ['Python 3.7']

    Activity

    1. vstinner commented on Dec 9, 2016

      @vstinner
      MemberAuthor

      This issue tracks changes to support the "fast call" calling convention in functions:

      • PyObject_CallFunctionObjArgs()
      • PyObject_CallMethodObjArgs()
      • _PyObject_CallMethodIdObjArgs()

      A "stack" of Python objects is created to pass arguments to _PyObject_FastCall(). The goal is to avoid the creation of a temporary tuple to call functions.

      The patch serie changes slots (typeobject.c), so calling Python slots from Python should avoid completely the creation of temporary tuples to pass parameters.

      Microbenchmark on a simple class with an __int__() method, call int(o):

      int(o): Median +- std dev: [ref] 239 ns +- 13 ns -> [patch] 219 ns +- 14 ns: 1.10x faster (-9%)

      Microbenchmark on a simple class with an __getitem__() method, call o[100]:

      o[100]: Median +- std dev: [ref] 211 ns +- 11 ns -> [patch] 172 ns +- 11 ns: 1.23x faster (-19%)

      Comparison between Python 2.7, 3.5, 3.7 and 3.7+patch, 3.5 is used as the reference:

      int(o)

      ======

      Median +- std dev: [3.5] 271 ns +- 15 ns -> [3.7] 239 ns +- 13 ns: 1.13x faster (-12%)
      Median +- std dev: [3.5] 271 ns +- 15 ns -> [patch] 219 ns +- 14 ns: 1.24x faster (-19%)
      Median +- std dev: [3.5] 271 ns +- 15 ns -> [2.7] 401 ns +- 21 ns: 1.48x slower (+48%)

      o[100]
      ======

      Median +- std dev: [3.5] 206 ns +- 5 ns -> [3.7] 211 ns +- 11 ns: 1.02x slower (+2%)
      Not significant!
      Median +- std dev: [3.5] 206 ns +- 5 ns -> [patch] 172 ns +- 11 ns: 1.20x faster (-17%)
      Median +- std dev: [3.5] 206 ns +- 5 ns -> [2.7] 254 ns +- 15 ns: 1.23x slower (+23%)

    2. vstinner commented on Dec 9, 2016

      @vstinner
      MemberAuthor

      bench_slots.py: microbenchmark on __int__ and __getitem__ slots.

    3. python-dev commented on Dec 9, 2016

      python-devmannequin
      Mannequin

      New changeset b771cf37714b by Victor Stinner in branch 'default':
      Add _PyObject_FastCallVa() helper
      https://hg.python.org/cpython/rev/b771cf37714b

      New changeset 455169e87bb3 by Victor Stinner in branch 'default':
      Add _PyObject_CallFunctionVa() helper
      https://hg.python.org/cpython/rev/455169e87bb3

      New changeset dd0d162593c5 by Victor Stinner in branch 'default':
      modsupport: replace int with Py_ssize_t
      https://hg.python.org/cpython/rev/dd0d162593c5

      New changeset 69d5dcf31f4a by Victor Stinner in branch 'default':
      modsupport: replace int with Py_ssize_t
      https://hg.python.org/cpython/rev/69d5dcf31f4a

      New changeset c1414b182232 by Victor Stinner in branch 'default':
      Add _Py_VaBuildStack() function
      https://hg.python.org/cpython/rev/c1414b182232

      New changeset 69948a157507 by Victor Stinner in branch 'default':
      _PyObject_CallFunctionVa() uses fast call
      https://hg.python.org/cpython/rev/69948a157507

      New changeset b9eb35435178 by Victor Stinner in branch 'default':
      Don't parenthesis in _PyObject_CallMethodId() format
      https://hg.python.org/cpython/rev/b9eb35435178

      New changeset 67302e6caa29 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs()
      https://hg.python.org/cpython/rev/67302e6caa29

      New changeset 032cbdb596fe by Victor Stinner in branch 'default':
      build_struct_time() uses Py_BuildValue()
      https://hg.python.org/cpython/rev/032cbdb596fe

      New changeset 49a7fdc0d40a by Victor Stinner in branch 'default':
      time_strptime() uses PyObject_Call()
      https://hg.python.org/cpython/rev/49a7fdc0d40a

      New changeset 6e748eb79038 by Victor Stinner in branch 'default':
      Add _PyObject_VaCallFunctionObjArgs() private function
      https://hg.python.org/cpython/rev/6e748eb79038

      New changeset adcd9131b7c6 by Victor Stinner in branch 'default':
      Use _PyObject_FastCallVa() in type slots
      https://hg.python.org/cpython/rev/adcd9131b7c6

    4. python-dev commented on Dec 9, 2016

      python-devmannequin
      Mannequin

      New changeset 39bed12135c1 by Victor Stinner in branch 'default':
      Issue bpo-28915: Use _PyObject_CallNoArg()
      https://hg.python.org/cpython/rev/39bed12135c1

      New changeset b29c719d5992 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs() in _asyncio
      https://hg.python.org/cpython/rev/b29c719d5992

    5. python-dev commented on Dec 9, 2016

      python-devmannequin
      Mannequin

      New changeset 807688539b56 by Victor Stinner in branch 'default':
      Fix refleak introduced in change 032cbdb596fe
      https://hg.python.org/cpython/rev/807688539b56

      New changeset ceb22b8f6d32 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs() in _ctypes
      https://hg.python.org/cpython/rev/ceb22b8f6d32

      New changeset ef05cc5cc651 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs() in _elementtree
      https://hg.python.org/cpython/rev/ef05cc5cc651

      New changeset 5b41b92a7ccf by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs() in _datetime
      https://hg.python.org/cpython/rev/5b41b92a7ccf

      New changeset 434e76e0ee17 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs() in _io
      https://hg.python.org/cpython/rev/434e76e0ee17

      New changeset 4545a2293e01 by Victor Stinner in branch 'default':
      Use _PyObject_CallMethodIdObjArgs()
      https://hg.python.org/cpython/rev/4545a2293e01

      New changeset 4321f833a4e0 by Victor Stinner in branch 'default':
      Use PyObject_CallFunctionObjArgs()
      https://hg.python.org/cpython/rev/4321f833a4e0

    6. vstinner commented on Dec 9, 2016

      @vstinner
      MemberAuthor

      The main feature was implemented, so I close the issue.

      Enjoy faster slots! (Many other less important functions are also faster.)

    7. python-dev commented on Dec 15, 2016

      python-devmannequin
      Mannequin

      New changeset bec846dd92e8 by Victor Stinner in branch 'default':
      Fix _PyObject_CallFunctionVa(), use the small stack
      https://hg.python.org/cpython/rev/bec846dd92e8

    8. python-dev commented on Dec 27, 2016

      python-devmannequin
      Mannequin

      New changeset fa9933bf4ea0 by Serhiy Storchaka in branch 'default':
      Issue bpo-28915: Exclude _Py_VaBuildStack from the limited API.
      https://hg.python.org/cpython/rev/fa9933bf4ea0

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeperformancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions