Code compiles each time it triggered

I’ve deployed my Julia code to AWS using Docker containers with enabling multiple threads, The issue we are facing is whenever HTTP end point (Julia) has been triggered process is compiling every time since because of using multiple processes whatever available process is getting triggered.

I am working on approach to pre-compile the code using packagecompiler and create binary file using sysimage. I would like to check if this is the appropriate solution or can someone please shade some lights on this?

Yeah. PackageCompiler is exactly the right solution here.

@Oscar_Smith Thanks for prompt response, can you please let me know if i need to use precompile_execution_file keyword or precompile_execution_statement while compiling with sysimage? My docker entry point is julia - - project http_calc.jl, so is it okay if i compiled sysimage with all precompiled statements and list my sysimage.so as entry point?

Running a representative workload will make the sysimage better, although how much better is very application specific.

In my experience, precompile_execution_file is very useful if you can create a script that contains a representative workload and can run entirely non-interactively. In the case of an HTTP server, that could involve having minimalistic client code running in a separate asynchronous task in order to trigger the relevant endpoints in the server.

If having a non-interactive script becomes in some way too much work, it might be easier to create a precompile_statements_file in an interactive way ahead of PackageCompiler-time.

This would involve running your project like so:

julia --project --trace-compile=precompile_statements.jl http_calc.jl

and then using it for a bit interactively in order to exercise as many features as possible. You can feed PackageCompiler with the generated precompile_statements.jl file in order to have a larger fraction of you code baked in the system image. An example use of this technique is detailed in the PackageCompiler tutorial about OhMyREPL

Yes, your new entry point would look like

julia --project --sysimage http_calc_sysimage.so http_calc.jl

@ffevotte Thanks for your help! Yes, I am able to compile using precompile_statements_file and see huge difference in compilation time.

One issue i noticed was if any new function/package added to the code should we need to do same steps? Since currently it seems like pre_compile_statement file will be overwritten if we start compile trace again. Do we have any flag for not to overwrite it?