Solved Static build is slower than dynamic build
-
So Ive compiled my app statically, but Im noticing slower startup times.
Closing, then quickly opening the app has no noticable slowdown. This leads me to believe that it has something to do with some cache.I can reproduce this with an app as simple as a Hello World program
Why is static slower?
Im using QT6 on Windows btw
-
@Pedro-Beirao said in Static build is slower than dynamic build:
Why is static slower?
I guess because the binary is bigger as it includes all dependencies in one file. So, the loader has to load a bigger binary.
-
That makes sense, but I was hoping to know if anyone else experienced this. Maybe there is something wrong with my static Qt installation?
-
@Pedro-Beirao How long does it take actually? How big is the difference compared to shared libraries?
-
Shared is instantaneous, while Static takes up to 5 seconds.
This is a small app and being this slow is not an option -
@Pedro-Beirao 5 seconds is indeed a lot for a small app. You could try to run your app through a profiler to see where it spends most time (provided it is not the OS loader consuming all that time).
-
What profiler would you recommend?
-
@Pedro-Beirao That depends on your OS and compiler.
For Linux see https://stackoverflow.com/questions/2497211/how-to-profile-multi-threaded-c-application-on-linux
For Microsoft compiler I don't know (I don't use them), but there should be a profiler. -
Alright, thanks!
-
@Pedro-Beirao What's that 5 seconds actually measuring? To start main() or 5 seconds after it gets to main() to show a UI? And how big is your binary? And how did you build? -- Is this a debug build or an optimized build? Does your compiler have Link Time Optimizations enabled?
-
Profiled with VerySleepy, and it takes 5 seconds to start main().
Final static binary is 20mb
Happens with both debug and release builds.
I use Qmake and Mingw to compile and haven't enabled any LTOVerySleepy shows that the funtion ZwWaitLowEventPair from ntdll is the culprit of the slowdown, but I didnt find anything about it online
What LTO should I use?
-
Compiled Qt statically with -static-runtime enabled, and now the slowdown is gone.
Maybe finding libstdc++ and libgcc was slow.I'll still need to do some more testing, but Im positive that this was the problem