Embedding Julia in C++ jl_init is super slow

Hi, I’m completely new to Julia, from a mostly C++ background, and am very intrigued by it. I’m trying to embed Julia into C++ for a gaming application.
I copied and pasted the code in the docs (Embedding Julia · The Julia Language) using MSVC in Windows 10. I had a few errors like “No Target Architecture” and then jl_atomic_load_relaxed not found. When I got through those by googling for answers, I hit a problem that I don’t see an answer for.

int main(int argc, char** argv)
	jl_init(); // required init
	jl_eval_string("print(sqrt(2.0))"); // run from string
	jl_atexit_hook(0); // requred exit
	return 0;

The jl_init() line takes about 20 seconds every single time I run the app. Any idea what would be happening or how would I remedy it?

I have the environment variable JULIA_DIR set as well as the bin directory in the windows Path. I tried jl_init_with_image but got the same results. startup.jl is empty.

I’m running on a decent laptop i7-8750H with 32GB. I installed Julia on a local SSD where I run all my programming stuff and some high-performance games without issue; although not at the default location Julia suggested in the setup wizard. I’m on Julia version 1.6.2 64bit. I’m using visual studio 2019 v142.

I saw this post: Slow start up and package loading times - #7 by albertoguiggiani which also reported ~20 seconds to startup, but unfortunately it didn’t help narrow my problem down.

I tried grabbing latest binary again and letting it install in the default location on my C drive (an M.2 SSD), but got the same results. I also tried Julia 1.7.0beta4 64bit and had the same results.

Launching Julia.exe from a command prompt runs pretty much instantly.

I’ll be happy to debug this with anyone’s help in order to make Julia more beginner friendly for windows people like me.

IMPORTANT UPDATE: if I run the executable from the command line (>x64\embeddedjulia.exe), it runs fast; or hitting Ctrl+F5 in VS. It’s only super slow when running it using Visual Studio with F5 or “Start Debugging”. This indicates it might be symbol loading. I disabled loading symbols and it still happened. I can see the program stalling loading dlls though. Why is dll loading slower while debugging is the question.

UPDATE2: disabling Tools > Options > Debugging > General “Load debug symbols in external process” made the stall go from 21 seconds to about 12.


On your machine, if you just run the julia itself how long does it take to start? You’re not going to get faster than that, and maybe that’s 20 s on your machine?

on my linux machine it takes about 10-11 seconds to start julia from the command line the first time (it’s stored in my home dir on a NAS). After that it’s about 2-3 seconds to start it (i assume this is due to cache of the binary from the NAS). This is with 1.7.0-beta4.

If I open a command prompt (cmd) and I navigate to the Julia bin folder and type Julia.exe, it runs pretty much instantly. Also, running with Ctrl+F5 in VS or from the command line runs instantly.

1 Like

The answer does seem to be related to dll loading through the Visual Studio debugger; most probably loading symbols for all dlls getting loaded. In UPDATE2 I turned off symbol loading for external processes and it made it 2x faster. It’s still a bit annoying since I can’t figure out how to turn off loading symbols in all julia dlls getting loaded, but much better.

1 Like