-
Hello everybody! I am looking for a possibility to "compile a python script" to a native image. I wonder if it's possible with graal technology stack? I have a simple polyglot app, which evaluates a python string: print("Hello World"). I've compiled this app to java byte code and then to native image. I used native image with Is it possible to compile a python script (e.g. used by polyglot application) to a native image? Is there maybe a better approach to "compile a python script" to a native image? Thank you for every hint! Even a simple "yes", "no" or "not yet" would help me a lot! Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No. You can ship self-contained binaries with no external dependencies, but they will always contain the interpreter. Having interpreter-less AOT for Python is not really feasible due to how dynamic Python is, at least in the sense that a theoretical AOT implementation won't meet the performance/footprint expectations you'd have. In python basically everything can be redefined at runtime at any point. Modules, functions, types, attributes, builtins. You can even add/remove methods to/from types for which there are already instances, change types of existing objects, change existing type's superclass... The JIT only works by making a lot of assumptions that this and that won't change and it falls back to the interpreter when it does and recompiles later. Interpreter-less AOT would only be possible for some restricted subset of python that disallows all the dynamic features, like PyPy's RPython. AFAIK we currently don't plan doing that, the usefulness would be very limited, since it won't be compatible with most existing libraries and projects. We have experimented with saving some state from the JIT so that applications can start faster, but they still need to contain the interpreter as a fallback when assumptions don't hold. That being said there are ways to get better footprint or startup performance. You can omit components that you don't use from the image (docs). If your application is expected to be run as an one shot script that finishes quickly, you can omit the whole JIT (described in the same doc). |
Beta Was this translation helpful? Give feedback.
No. You can ship self-contained binaries with no external dependencies, but they will always contain the interpreter. Having interpreter-less AOT for Python is not really feasible due to how dynamic Python is, at least in the sense that a theoretical AOT implementation won't meet the performance/footprint expectations you'd have. In python basically everything can be redefined at runtime at any point. Modules, functions, types, attributes, builtins. You can even add/remove methods to/from types for which there are already instances, change types of existing objects, change existing type's superclass... The JIT only works by making a lot of assumptions that this and that won't change and i…