Author vstinner
Recipients Solomon Ucko, Trundle, benjamin.peterson, eric.araujo, ezio.melotti, georg.brandl, python-dev, vstinner
Date 2019-03-07.11:38:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551958721.3.0.251364497442.issue11614@roundup.psfhosted.org>
In-reply-to
Content
> The byte code could be further optimized (because this is such a speed-critical module! :)): (...)

You propose to replace

              8 CALL_FUNCTION            1
             10 POP_TOP
             12 LOAD_CONST               2 (None)
             14 RETURN_VALUE

with:

             12 CALL_FUNCTION            1 
             15 RETURN_VALUE

It changes the semantics of Python. Technically, you *can* override the print() builtin function:

vstinner@apu$ ./python
Python 3.8.0a2+ (heads/master:dc078947a5, Mar  7 2019, 12:23:23) 
>>> import builtins
>>> def mock(*args, **kw): return 3
... 
>>> builtins.print=mock
>>> print("hello")
3
>>> import __phello__
>>> # doesn't print anything
... 

It would be possible if you ensure that print() isn't replaced.

Longer explanation:
https://fatoptimizer.readthedocs.io/en/latest/semantics.html

To use more efficient bytecode without modying the Python semantics, you need to deoptimize if print() is replaced. I implemented that in my old FAT Python project :-)
https://fatoptimizer.readthedocs.io/en/latest/optimizations.html#call-pure

--

I would be more interested by a tool to update/regenerate M___hello__ in Python/frozen.c.
History
Date User Action Args
2019-03-07 11:38:41vstinnersetrecipients: + vstinner, georg.brandl, benjamin.peterson, ezio.melotti, eric.araujo, Trundle, python-dev, Solomon Ucko
2019-03-07 11:38:41vstinnersetmessageid: <1551958721.3.0.251364497442.issue11614@roundup.psfhosted.org>
2019-03-07 11:38:41vstinnerlinkissue11614 messages
2019-03-07 11:38:41vstinnercreate