New submission from Serhiy Storchaka: Currently PyObject_IsTrue() is called every time when bool attributes (_json.Scanner.strict, _json.Encoder.sort_keys, _json.Encoder.skipkeys) are used in C acceleration of the json module. PyObject_IsTrue() is fast when the argument is a bool, but in any case this isn't efficient and is cumbersome. It is better to convert Python bool to C boolean value only once when create an object, as already is done for _json.Encoder.allow_nan and for most other boolean values in extension modules.
Proposed patch simplifies and optimizes the code by making arguments strict, sort_keys and skipkeys be converted only once at argument parsing time. The patch changes behavior in the case when the boolean value of the argument is not constant. But this is very bad practice, we may ignore this obscure case (as ignore the case when the boolean value of the container doesn't consistent with its content, see issue27613). ---------- components: Extension Modules messages: 292861 nosy: bob.ippolito, ezio.melotti, rhettinger, serhiy.storchaka priority: normal severity: normal stage: patch review status: open title: Using boolean arguments in the _json module type: performance versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30248> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com