[New-bugs-announce] [issue11856] Optimize parsing of JSON numbers

Antoine Pitrou report at bugs.python.org
Sat Apr 16 14:19:22 CEST 2011


New submission from Antoine Pitrou <pitrou at free.fr>:

In Python 3.x, parsing JSON numbers involve calling PyLong_FromUnicode or PyFloat_FromString with an unicode object. These functions are quite costly because they call PyUnicode_TransformDecimalToASCII(). But JSON numbers are always pure ASCII. This patch does the ASCII conversion ourselves.

Small benchmark with integers:
./python -m timeit -s \
  "from json import loads, dumps; d=list(i for i in range(1000)); s=dumps(d)" \
  "loads(s)"

-> without patch: 705 usec per loop
-> with patch: 103 usec per loop

----------
components: Library (Lib)
files: jsonnumbers.patch
keywords: patch
messages: 133891
nosy: mark.dickinson, pitrou, rhettinger
priority: normal
severity: normal
stage: patch review
status: open
title: Optimize parsing of JSON numbers
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file21681/jsonnumbers.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11856>
_______________________________________


More information about the New-bugs-announce mailing list