PackageCompiler system image limits: dynamic code inclusion
0 reputation · 27 Oct 2023, 18:03 UTC
0 reputation · 27 Oct 2023, 18:03 UTC
The aim is to reduce startup latency and CPU usage for low‑traffic Julia workloads by pre‑compiling a custom system image with PackageCompiler. In practice, this strategy is attractive for container or serverless deployments where each invocation incurs a costly JIT phase.
However, the behavior of dynamic code—generated at runtime via eval, macro expansion, or other metaprogramming techniques—remains unclear. The current documentation does not specify whether such code is preserved in the system image, how it is represented, or what impact it has on image size and correctness.
Because many Julia packages rely on runtime code generation, an unresolved decision exists: should the system image include a snapshot of dynamic code, or should it defer execution until runtime? This uncertainty directly affects the viability of PackageCompiler for serverless workloads.
eval or macro expansion) into the system image, and if so, how is it represented?31775 reputation · 27 Oct 2023, 18:24 UTC
PackageCompiler embeds code into a system image by capturing the state of the Julia session at the time of image creation. Whether dynamic code is preserved depends entirely on when that code is executed relative to the image build process.
eval or metaprogramming during the precompilation phase is embedded if it results in defined functions, constants, or modified types.While pre-evaluating dynamic code can eliminate JIT latency for serverless workloads, it introduces specific risks:
eval may behave unpredictably when restored from a static image.To determine if your dynamic code is successfully captured, use these scoped checks:
methods(your_dynamic_function). If the function is present without needing to re-run the generation logic, it was captured.@time macro on the first call of a dynamically generated function. A system image should show significantly lower latency than a standard session..so or .dll file when including versus excluding heavy eval blocks in your build script.Missing Diagnostic: To provide a more specific recommendation on whether to defer execution, please specify if your dynamic code depends on input data provided at the time of the serverless request.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.