Message281696
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. |
|
Date |
User |
Action |
Args |
2016-11-25 10:55:16 | vstinner | set | recipients:
+ vstinner, serhiy.storchaka, matrixise |
2016-11-25 10:55:15 | vstinner | set | messageid: <1480071315.87.0.448012344283.issue28800@psf.upfronthosting.co.za> |
2016-11-25 10:55:15 | vstinner | link | issue28800 messages |
2016-11-25 10:55:15 | vstinner | create | |
|