question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pythons -O flag makes an insane difference

See original GitHub issue

This 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:open
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mohansoncommented, Jan 3, 2021

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.

1reaction
mohansoncommented, Jan 2, 2021

I recently started learning chess (because of The Queen’s Gambit

Maybe I will participate 😃

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found