-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-2506: Experiment with adding a "-X noopt" flag #9693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@1st1 thanks! |
I'm in favor of being able to disable the peephole optimizer, but I wonder if we need to rethink how we do |
Test filea = 1 + 2
while 3:
print(a)
b = 4 With
|
@warsaw I'd be OK with |
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. |
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 |
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 |
Ah, got it. |
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 |
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. |
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
When you're done making the requested changes, leave the comment: |
…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 What are your thoughts about pushing this forward? |
@1st1 I would love to see this progress. Is there something I can do to help? |
Victor's patch has been closed and followed by Pablo Salgado's #22027. |
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 noopt
or-O0something
file.noopt.cpython-38.pyc
)compile.c
and 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)