[issue23493] optimize sort_keys in json module by using operator.itemgetter()

Wouter Bolsterlee report at bugs.python.org
Fri Feb 20 17:25:56 CET 2015


New submission from Wouter Bolsterlee:

The JSON encoder uses a lambda function for the sort(key=...) invocation used to sort the keys in a JSON object in case sort_keys=True is passed:

https://hg.python.org/cpython/file/46bfddb14cbe/Lib/json/encoder.py#l352

Instead of having a lambda, operator.itemgetter(0) can be used here, which is a minor performance gain. It should be noted that many other internals of the JSON encoder have also been fine-tuned (manually) for performance reasons.

----------
components: Library (Lib)
messages: 236302
nosy: wbolster
priority: normal
severity: normal
status: open
title: optimize sort_keys in json module by using operator.itemgetter()
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

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


More information about the Python-bugs-list mailing list