# Embedding Julia in C++ jl\_init is super slow

**URL:** <https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [September 2, 2021, 5:54am UTC](https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549 "2021-09-02T05:54:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/solaris/32/28875_2.png) [@solaris](https://discourse.julialang.org/u/solaris)\
**Post date:** [September 2, 2021, 5:54am UTC](https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549/1 "2021-09-02T05:54:50Z")

</div>

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](https://docs.julialang.org/en/v1/manual/embedding)) 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.

```julia
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](https://discourse.julialang.org/t/slow-start-up-and-package-loading-times/52639/7) 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.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [September 2, 2021, 8:11pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549/2 "2021-09-02T20:11:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![solaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/solaris/32/28875_2.png) [@solaris](https://discourse.julialang.org/u/solaris)\
**Post date:** [September 2, 2021, 8:15pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549/3 "2021-09-02T20:15:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![solaris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/solaris/32/28875_2.png) [@solaris](https://discourse.julialang.org/u/solaris)\
**Post date:** [September 3, 2021, 8:49pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-jl-init-is-super-slow/67549/4 "2021-09-03T20:49:13Z")

</div>

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.
