Julia image threads on Windows

As far as I know, by default PackageCompiler uses JULIA_IMAGE_THREADS=1 on Windows and all cores on Linux (Julia v1.10) due to which it completes much faster on Linux, but uses more RAM. I set on Windows system variable to 12 which is my number of cores, but that did not appear to do anything. Does Julia support using more than 1 image thread on Windows? Is this missing feature or a bug? Can Linux behavior of parallelism be recreated on Windows?

It does not support that because of limitations of the linker on Windows. The parts created by different threads need to be linked together. I do not know if a work-around for this problem would be possible. See: High number of external symbols in Windows 10 when creating sysimages with julia 1.10.0-beta1 ¡ Issue #50954 ¡ JuliaLang/julia ¡ GitHub

The open - and unanswered - question in this issue is, why does the package compiler add --export-all-symbols to the linker parameters which results in too many symbols.

2 Likes

Thank you for detailed answer. I am looking forward if someone will be fixing this.

Besides functionality, it is not in documentation that this is not working on Windows.

Perhaps you can create an issue “Missing support for multi-threaded system image creation on Windows” in the package PackageCompiler.jl ? To make this work probably changes to both PackageCompiler.jl and Julia are required.

People are working on fixing this, and if I’m reading correctly, have already done so on master that you can try checking out, I’m not on Windows to test, but curious if it works):

using Pkg

Pkg.add(PackageSpec(url="https://github.com/JuliaLang/PackageCompiler.jl", rev="master"))

in case I'm wrong about master, check out that PR/commit:

Pkg.add(PackageSpec(url="https://github.com/JuliaLang/PackageCompiler.jl", rev="0f2d3b70cff4a72fd77d0af68de93e2491abd346"))

Note, it was limited to 1 thread, by design, as a workaround, that’s now apparently no longer needed:

This was a problem on 1.11, but less of a problem on 1.10? I hope both fixed now, and if not try either with fewer threads > 1.

Julia does for sure support threads on Windows too. This was only a problem while compiling. I think, though not sure, that you could compile with 1 thread to make the compiling work, but then when using that compiled code have as many threads as you like.

No, it does NOT support multi-threaded system image generation on Windows. The issue you are referring here is a very different issue. It was more an issue on Linux when creating a non-incremental system image. Creating an incremental system image using multiple threads on Linux always worked and still works, at least with Julia 1.10 and 1.11. It does not work multithreaded on Windows. Not sure if it was always like that or if there are old Julia versions where it still works.

I created the issue on PackageCompiler.jl.

1 Like

I closed the issue at PackageCompiler.jl as I thought that PR #59736 resolves it (included with 1.12.1). However, now I am not so sure that it is resolved as compilation time for my case is longer on Windows that Linux. However, I am observing massive regression in compilation time from 1.11 to 1.12 even on Linux so if someone else could evaluate on some other example that would be great. If needed I can reopen the issue if not resolved.

Did anyone try it if it is resolved with latest 1.12? I am observing very significat compile time regression with 1.12 (even on linux) so hard to say.

Yes, with Julia 1.12.2, Julia image creation happens threaded. My test script for installing a large package and creating a system image takes about 15min on Linux and 26min on Windows (in a virtual machine) now. Just the system image creation on Windows takes about 7 min. Single threaded the numbers are 34min and 14 min, so the image threads save 7-8 minutes. I will try to add a comparison against Linux in virtual machine (which would be fairer) when I find the time.

Important: I use the following code to switch between single and multi-threaded system image creation:

# Check memory and limit threads if needed
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
    # Windows: use wmic or PowerShell
    echo "Checking system memory on Windows..."
    totalmem=$(powershell.exe -Command "(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB" 2>/dev/null | awk '{printf "%i", $1}')
    if [[ -z "$totalmem" || $totalmem -lt 27000 ]]; then
        echo "Warning: Less than 27GB of memory detected on Windows. Using only one thread for sysimage compilation."
        export JULIA_IMAGE_THREADS=1
    fi
else
    # Linux: use /proc/meminfo
    totalmem=$(grep MemTotal /proc/meminfo | awk '{printf "%i", $2 / 1024}')
    if [[ $totalmem -lt 27000 ]]; then
        echo "Warning: Less than 27GB of memory detected. Using only one thread for sysimage compilation."
        export JULIA_IMAGE_THREADS=1
    fi
fi

For multithreaded image generation, at least 27GB of RAM are needed.

1 Like