Statically build program is slower.
-
Hi,
I have compiled my application dynamically and statically using Qt 5.6.2 under
windows 7. Running speed seems similar. But when I start the program, program loading speed seems different as following,
Dynamic: 1.6 second
Static: 2.2 second
So statically build program feels heavier to start. I thought, because static build has smaller files size, it must be faster to load.I copy the program to windows 10 machine, the difference is more clear
Dynamic: 1.4 second
Static: 5.5 secondI don't understand why it takes too long to start statically build program in
windows 10. Do I have to compile statically under windows 10 to make it faster
to start?.pro file loos like
QT += multimedia
QT += svg
qtHaveModule(printsupport): QT += printsupport
and it includes 2 external library files -
Hi @samdol
So statically build program feels heavier to start.
yeah, sure, because now all code has to be loaded at startup. on dynamic linking, the library code loading can be delayed, in worst case until the library functions are use first..
i don't think compiling on W10 will make a difference. CPU, RAM and HD speed will.
-
@aha_1980
Does that mean it is almost always better to compile dynamically as far as concerning loading time?
So may I summarize pros/cons as following?
Dynamic : faster launching speed, but large number of files taking big disk space.
Static : Single executable smaller size file, but slower launching speed.Is there any other advantages to compile statically?
-
Hi
The biggest advantages (IMHO) from static linking is the single exe. There are no external
dependencies that must be included , nor is it possible to crash due to wrong/unexpected version of a DLL/so file. You are also less prone to injection attacks and the the whole maintenance complexity is reduced. -
@samdol If you have many programs using the libraries, dynamic libraries will be much smaller in aggregate than a bunch of individual static binaries all carrying around a copy of the library. Static binaries are really only likely to be smaller when you only consider the case of a single binary that has unused functionality stripped out. As soon as you have multiple binaries sharing the library, or the binary links to all the functions of the library, it's not a benefit.
There's a reason people invented shared libraries, you know!
-
@samdol
Unless you have a very good reason, you always want dynamic not static libraries. If you mean the Qt was static/dynamic as well as other libraries, then not to mention, if you have any intention of distributing the Qt application you are building, and you want to be free...! -
@mrjj
I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files. Beside, even with all those advantages, from the end user's point of view, if the static binary(5.5 sec) is considerably slower than dynamic binary (1.4 sec) in launching, there seems no point to purchasing license for static compile. I still don't understand why my static app is considerably slower than dynamic app in windows 10. -
I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files.
@samdol How large is the search path for the libraries? If some commenters on the Internet say static binaries are faster and your stopwatch says they aren't, which will you believe?
On Linux, you can use something like strace and fiddle with LD_LIBRARY_PATH to measure how long the search process takes as you add additional candidate directories . Hint: in general it's not very large. If it wasn't, systems wouldn't use dynamic libraries so much. If the libraries are already in memory (because shared) then it's just coming out of page cache and the filesystem overhead to get to the code in the libraries will be small.
I still don't understand why my static app is considerably slower than dynamic app in windows 10.
It's much larger, for starters. Past that, use a profiler! Measure it! Random strangers on the internet can't possibly know more about what your computer is doing with your code than you can!