Title: json module: encoder optimization
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Marian Horban 2, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-04-20 09:15 by Marian Horban 2, last changed 2017-04-20 10:36 by serhiy.storchaka. This issue is now closed.

File name Uploaded Description Edit
encoder_opt.patch Marian Horban 2, 2017-04-20 09:15 review
Messages (2)
msg291955 - (view) Author: Marian Horban (Marian Horban 2) Date: 2017-04-20 09:15
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)
>>> def fbuilt_in():
...     for i in range(5):
...         x = False
>>> timeit.timeit("fbuilt_in()", "from __main__ import fbuilt_in", number=10000000)
msg291960 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-20 10:36
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.
Date User Action Args
2017-04-20 10:36:21serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg291960

resolution: rejected
stage: resolved
2017-04-20 09:15:30Marian Horban 2create