compiler-explorer / infra

Infrastructure to set up the public Compiler Explorer instances and compilers

Home Page:https://godbolt.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[julia] Use package for the wrapper to speed up compilation

giordano opened this issue · comments

I created a small Julia package, CompilerExplorer.jl, which simply replicates what the Julia wrapper in Compiler Explorer currently does. The code in that wrapper would simply become

using CompilerExplorer

CompilerExplorer.main()

The significant advantage is that when Julia code is saved into a package, it can cache some precompile code (and from Julia v1.9 onwards also native code), which can significantly improve runtime performance for the first run, as the methods called don't need to be JIT-compiled (or not as much extensively). Note that here I'm talking about the compilation of the functions calling the compiler infrastructure to eventually compile the code the user inputs in Compiler Explorer, that code will of course still have to be compiled regularly, but at least that'd be where most of the time will be spent.

As an example, for the default example code for the Julia language, in my local Compiler Explorer instance I get runtime going down from ~1800 ms with the current version of the wrapper
image
to ~400 ms with using the package
image

Using this package would also make testing easier for us for all versions, and hopefully avoid silly mistakes like compiler-explorer/compiler-explorer#5927 (comment).

I'm happy to make a PR to make this happen, but I want to understand whether this would be effective in the production version of Compiler Explorer. If we install this package during the installation of the Julia toolchain here, can we cache its precompiled code? By default Julia stores it in the ~/.julia/compiled directory, but the location can be changed with the environment variable JULIA_DEPOT_PATH, to accommodate whatever caching infrastructure is used here.

CC: @vchuravy

So if it's user-code independent caching, yes we definitely can do it during installation. But we'll have to save it to a read-only directory on the installation path in /opt/compiler-explorer/julia-version/.julia/compiled - or potentially copy the directory to a writeable /tmp directory during usage by users, but any changes done to the directory cannot persist.

That is sensible. We could be cute and just install it into the stdlib location.

So /opt/compiler-explorer/julia-v1.10/share/julia/stdlib/v1.10/CompilerExplorer and then we can do JULIA_DEPOT_PATH=/opt/compiler-explorer/julia-v1.10/share/julia/ julia -e "using CompilerExplorer" to create the cache file in the right location.

@partouf is an after_stage_script like

after_stage_script:
the right tool here?

@partouf is an after_stage_script like

after_stage_script:

the right tool here?

Yes, correct

Is there a way to access the source of compiler-explorer/compiler-explorer within the staging process? It would probably make sense to vendor the source there since the output of it is coupled to the compiler invocation there.

Or is the infra stage independent of the compiler-explorer deployment

they are independent, but you could curl https://raw.githubusercontent.com/compiler-explorer/compiler-explorer/main/somethingsomethingsomething

But for Julia nightly the script will run every night when it's being re-installed, just not for the fixed versions

Thank you so much for the explanations! A start to address this issue is in #1264.