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

json module: encoder optimization #74297

Closed
MarianHorban2 mannequin opened this issue Apr 20, 2017 · 2 comments
Closed

json module: encoder optimization #74297

MarianHorban2 mannequin opened this issue Apr 20, 2017 · 2 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@MarianHorban2
Copy link
Mannequin

MarianHorban2 mannequin commented Apr 20, 2017

BPO 30111
Nosy @serhiy-storchaka
Files
  • encoder_opt.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 = None
    closed_at = <Date 2017-04-20.10:36:21.415>
    created_at = <Date 2017-04-20.09:15:30.868>
    labels = ['library', 'performance']
    title = 'json module: encoder optimization'
    updated_at = <Date 2017-04-20.10:36:21.413>
    user = 'https://bugs.python.org/MarianHorban2'

    bugs.python.org fields:

    activity = <Date 2017-04-20.10:36:21.413>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-04-20.10:36:21.415>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2017-04-20.09:15:30.868>
    creator = 'Marian Horban 2'
    dependencies = []
    files = ['46815']
    hgrepos = []
    issue_num = 30111
    keywords = ['patch']
    message_count = 2.0
    messages = ['291955', '291960']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'Marian Horban 2']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue30111'
    versions = ['Python 2.7']

    @MarianHorban2
    Copy link
    Mannequin Author

    MarianHorban2 mannequin commented Apr 20, 2017

    It is possible to improve performance of json module encoder.
    Since access to local variables is faster than to globals/builtins I propose to use locals instead of globals.
    Small test of such improvement:

    >>> import timeit
    >>> def flocal(name=False):
    ...     for i in range(5):
    ...         x = name
    ... 
    >>> timeit.timeit("flocal()", "from __main__ import flocal", number=10000000)
    5.0455567836761475
    >>> 
    >>> def fbuilt_in():
    ...     for i in range(5):
    ...         x = False
    ... 
    >>> 
    >>> timeit.timeit("fbuilt_in()", "from __main__ import fbuilt_in", number=10000000)
    5.451796054840088

    @MarianHorban2 MarianHorban2 mannequin added stdlib Python modules in the Lib dir performance Performance or resource usage labels Apr 20, 2017
    @serhiy-storchaka
    Copy link
    Member

    New features can be only added to the default branch. True and False are not global variables but keywords in Python 3. And in any case the json module is accelerated by C implementation which much faster than any microoptimized Python code.

    @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
    performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant