This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients matrixise, serhiy.storchaka, vstinner
Date 2016-11-25.10:55:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480071315.87.0.448012344283.issue28800@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-11-25 10:55:16vstinnersetrecipients: + vstinner, serhiy.storchaka, matrixise
2016-11-25 10:55:15vstinnersetmessageid: <1480071315.87.0.448012344283.issue28800@psf.upfronthosting.co.za>
2016-11-25 10:55:15vstinnerlinkissue28800 messages
2016-11-25 10:55:15vstinnercreate