Pythons -O flag makes an insane difference
See original GitHub issueThis is just something I noted
Running a script that spends most of its time in pywasm’s exec:
$ time python main.py
real 2m0,034s
user 2m0,305s
sys 0m0,644s
And with optimizations enabled:
$ time python -O main.py
real 0m0,449s
user 0m0,908s
sys 0m0,481s
According to this -O eliminates assert statements. Not sure how much this impacts security.
Edit: ok, it seems that the code is not executed correctly, I’ll have a look
I get this:
File "main.py", line 193, in play
runtime = pywasm.load(runtime, {
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/__init__.py", line 98, in load
module = binary.Module.from_reader(f)
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 1084, in from_reader
type_section = TypeSection.from_reader(section_reader)
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 445, in from_reader
o.data = [FunctionType.from_reader(r) for _ in range(n)]
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 445, in <listcomp>
o.data = [FunctionType.from_reader(r) for _ in range(n)]
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 70, in from_reader
o.args = ResultType.from_reader(r)
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 51, in from_reader
o.data = [ValueType.from_reader(r) for i in range(n)]
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 51, in <listcomp>
o.data = [ValueType.from_reader(r) for i in range(n)]
File "/home/one/.pyenv/versions/3.8.2/lib/python3.8/site-packages/pywasm/binary.py", line 33, in from_reader
return ValueType(ord(r.read(1)))
Exception ord() expected a character, but string of length 0 found
Ah, looking through the pywasm code it seems that the asserts have side effects, that are necessary for it to be executed correctly.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
What are the implications of running python with the optimize ...
From What does the -O flag do? It somewhat depends on the Python version. To find out precisely what it does, search the...
Read more >A Python code structure problem: exception handling with flags
The first approach is to use isinstance() on e to tell what sort of exception we have and then write out the conditions...
Read more >How to make mistakes in Python - O'Reilly
How to make mistakes in Python. Experienced programmer Mike Pirnat shares some of his most memorable blunders. By avoiding these missteps, ...
Read more >satwikkansal/wtfpython: What the f*ck Python? - GitHub
Okay Python, Can you make me fly? ... So even though 5 , 5.0 , and 5 + 0j are distinct objects of...
Read more >8 Reasons Python Sucks - The Hacker Factor Blog
Two concurrent projects with two different versions of Python -- no, ... That is, until you start making large code bases.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I fixed the side effects of assertion in
pywasm==1.0.7
, and at the same time improved the performance (about ~10%). I think I have a chance to double the running speed, but I need to think more (that is, not in this version).-O
won’t break the program anymore.I recently started learning chess (because of The Queen’s Gambit
Maybe I will participate 😃