Import local python code takes long #3192
-
Bug DescriptionI want to import a module i have in python, which is quite big. I imported it as seen below. I am using pyo3_asyncio to execute a function from this package which takes about 30sec to run, but the time it takes to import is 2 seconds. Steps to ReproducePython::with_gil(|py| { BacktraceNo response Your operating system and versionArch Linux Your Python version (
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Are you sure this is a bug rather than a discussion? Does importing the module from Rust is measurably slower than import it from Python? |
Beta Was this translation helpful? Give feedback.
-
in python i can just execute the code. I am looking for a way to load python code without the time to wait. The execution time is just slighlty worse in rust(2%) |
Beta Was this translation helpful? Give feedback.
I don't think this is possible in general as importing a Python module can execute arbitrary code, so there is most likely no easy fix.
As this does depend on the specific module in question, you could start with trying to find out what exactly is taking too long. Some Linux distributions try to improve load times by shipping pre-compiled byte code (
.pyc
files, c.f. https://docs.python.org/3/library/py_compile.html) but that only helps if the time is actually spent parsing source code into byte code.