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.

nuitka binaries slow performance with Python3 in-place string add

See original GitHub issue

Nuitka version:

0.6.0rc4
Python: 3.6.6 (default, Sep 12 2018, 18:26:19) 
Executable: /usr/bin/python3
OS: Linux
Arch: x86_64

Installed via: apt

Greetings,

Really love this project. Thanks for all your hard work on it. My nuitka binaries generally perform really well, even for complex projects. The one exception is when I implement code that generates a large volume of random numbers. The code below is much slower in a nuitka build when compared to running it in the python3 interpreter:

chars = []
for i in range(256):
   chars += [chr(i)]
wrapper = ""
for i in range(10000000):
   wrapper += random.choice(chars)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
geozekecommented, Sep 25, 2018

Thank you again! I can see how creating strings (which are immutable in python) would be a waste. I re-factored the code to use lists rather than strings, with a final .join() at the end, and it is indeed much faster in nuitka. It now looks like this:

n = 10000000

chars = []
for i in range(256):
   chars += [chr(i)]

wrapper = ['*'] * n
for i in range(n):
   wrapper[i] = random.choice(chars)

s = "".join(wrapper)

0reactions
kayhayencommented, Mar 26, 2021

This has long been resolved by recent changes that avoid the CPython API for in-place operations on these types. In Nuitka 0.6.13 this should no longer happen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuitka: An extremely compatible Python compiler - Hacker News
It's slower than pypy, but starts faster and results in a standalone executable. Also, it's compatible with most c extensions.
Read more >
Nuitka-fixed - PyPI
Nuitka is the Python compiler. It is written in Python. It is a seamless replacement or extension to the Python interpreter and compiles...
Read more >
Nuitka - Gitee
Nuitka is a Python compiler written in Python. ... and this even happens to the DLL with itself, being slower, than a Python...
Read more >
Programming FAQ — Python 3.11.1 documentation
Performance. My program is too slow. How do I speed it up? What is the most efficient way to concatenate many strings together?...
Read more >
Compiling Python Code to Executable with nuitka
Avoid running the nuitka binary, doing python -m nuitka will make a 100% sure you are using what you think you are. Using...
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