STINNER Victor <vstin...@redhat.com> added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue11614>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to