Performance difference between static and shared library

4

Which is the best in performance? Compile the program using libraries such as MySQL Connector and SQLite as static (getting inside the compiled binary) or as shared getting separated from the binary.

In addition, can you use a shared library in a subfolder instead of getting binary executable?

    
asked by anonymous 13.04.2016 / 03:42

1 answer

4

On load the dynamic library will have to mount a table where the symbols are available. The difference is very small and will not make any difference. There may be gain in library load which may already be in memory. Because it can conserve memory consumption, there may be a gain because it is more likely to be cached.

There may be an overhead in function calls, as this test .

In applications that use database, where minimal access is absurdly more expensive than the executable load, it will not affect anything significantly.

It is possible in some situations to get better performance because of better optimization if statically compiling. And it may have some gain by reference location. Do not expect miracles, or make a difference in most applications.

I particularly prefer static compilation whenever possible.

You can put the compiled libraries in folders where the system is instructed to search by default or the application knows in some way that you should search these locations. This is usually a headache and today is largely avoided. We are no longer in time for this to be an advantage.

It is best to leave the libraries dynamic when it is something that the operating system already has unambiguously or whether it will create a plugin / hot patch system.

This can be useful .

You have more details about this in What's the difference between static and dynamic linking?

    
13.04.2016 / 04:13