[New-bugs-announce] [issue28800] Add RETURN_NONE
STINNER Victor
report at bugs.python.org
Fri Nov 25 05:55:15 EST 2016
New submission from STINNER Victor:
Attached patch adds a new bytecode instruction: RETURN_NONE. It is similar to "LOAD_CONST; RETURN_VALUE" but it avoids the need of adding None to constants of the code object. For function with an empty body, it reduces the stack size from 1 to 0.
Example on reference Python 3.7:
>>> def func(): return
...
>>> import dis; dis.dis(func)
1 0 LOAD_CONST 0 (None)
2 RETURN_VALUE
>>> func.__code__.co_stacksize
1
Example on patched Python 3.7:
>>> def func(): return
...
>>> import dis; dis.dis(func)
1 0 RETURN_CONST
>>> func.__code__.co_stacksize
0
If the function has a docstring, RETURN_CONST avoids adding None to code constants:
>>> def func():
... "docstring"
... return
...
>>> func.__code__.co_consts
('docstring',)
I will now run benchmarks on the patch.
----------
files: return_none.patch
keywords: patch
messages: 281696
nosy: haypo, matrixise, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Add RETURN_NONE
versions: Python 3.7
Added file: http://bugs.python.org/file45640/return_none.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28800>
_______________________________________
More information about the New-bugs-announce
mailing list