bpo-2506: Experiment with adding a "-X noopt" flag#9693
Conversation
|
I'm in favor of being able to disable the peephole optimizer, but I wonder if we need to rethink how we do |
Sorry, something went wrong.
Test filea = 1 + 2
while 3:
print(a)
b = 4With
|
Sorry, something went wrong.
|
@warsaw I'd be OK with |
Sorry, something went wrong.
We already have three switchable compilation behaviors: peephole, NDEBUG (
Arguably, it might be useful to be able to enable docstring stripping without stripping What's not clear at all is how this would interact with the bytecode cache. |
Sorry, something went wrong.
We also have an AST optimizer (and Inada-san is working on making it possible to have that optimizer in Python). To simplify things we can make
I agree. Some packages [ab]use docstrings for meta programming and it's not possible to use those packages with
One option is to assign a bit flag to every |
Sorry, something went wrong.
Once the number of flags grows, this would quickly become unmaintainable, as system-installed packages will have to generate a .pyc for every flag combination. A solution for this is to allow writing the bytecode cache to a user-writable directory, which, together with |
Sorry, something went wrong.
Ah, got it. |
Sorry, something went wrong.
|
The main problem is interaction with the bytecode cache. See previous discussion. This option should either blindly There are other optimizations in bytecode generation. No bytecode is generated for |
Sorry, something went wrong.
|
I appreciate all of the activity! For my purposes, emitting lines for "else:" and "pass" isn't necessary, but I understand the philosophy of doing it. |
Sorry, something went wrong.
|
@elprans E.g. "-O[no-]peephole, -O[no-]strip-debug, and -O[no-]strip-doc" idea, there should be an open issue for this because @ambv has asked for the ability to turn off everything but And with |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
The .pyc filename should be different. I suggest ".noopt.pyc" suffix.
At least cache_from_source() and source_from_cache() of importlib._bootstrap_external have to be modified.
It's a little bit surprising to have sys.flags.optimize and sys.flags.noopt_mode. It seems redundant and a source of inconsistency, no? Would it be possible to modify sys.flags.optimize and _PyCoreConfig.optimization_level instead? For example, change the default optimization to level to 1, -X noopt would use 0.
Problem: doctest is hardcoded to skip tests if the optimization level is greater or equal to 2. doctest can easily be fixed, but maybe other 3rd party modules are hardcoded to rely on an exact optimization level.
Sorry, something went wrong.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
…ytecode. The patch (well, Py_INCREF) is based on python#9693 . Unlike that patch, this just forcibly skips optimizer, no command-line params, etc. The purpose if producing reference bytecode output for initial stages of https://github.com/pfalcon/python-compiler upgrade to produce CPython3.5 compatible bytecode (later it's expected to implement peephole optimizer in Python, to use unmodified CPython code).
|
@1st1 I would love to see this progress. Is there something I can do to help? |
Sorry, something went wrong.
|
Victor's patch has been closed and followed by Pablo Salgado's #22027. |
Sorry, something went wrong.
I've created this PR to evaluate if we can add the
-X noopt(or similar) option. So far I've done the following basic things:while <const>andif <const>constructsPartial list of ToDo's
-X nooptor-O0somethingfile.noopt.cpython-38.pyc)compile.cand disable micro-optimizations (like avoiding evaluating test cases of loops inwhile [constant]etc)I don't have time to implement everything myself right now, but it might be a good idea to ask @elprans to work on this one in the next couple of months (@vstinner currently mentors Elvis.)
https://bugs.python.org/issue2506
(See also https://bugs.python.org/issue34888)