Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Pleas help -> Dll vs StaticLib

vetroxl
Beginner
642 Views
Hello,
I am very baffled by the following issue. If I compile my code as a static lib I get very good performance on my decoding functions ~2.9ms. However, when I compile it as a dll the performance drops down to ~4.1ms. The code is identical, I just toggle where I call ippInit(); when it's a dll I call it in the DLL Main function, when it's a static I call it in the WinMain function. Can someone please give me some insight on what is going on?
Thanks,
0 Kudos
1 Solution
PaulF_IntelCorp
Employee
642 Views
The reasons for time delays associated with loading a shared library are application and OS dependent, other than the delayed load feature used by the IPP 6.1 library, the libraryhas very little control over this issue. You might want to search the web for detailed articles regarding the pros and cons of linking statically versus dynamically.

When you load a statically-linked application your application EXE includes all of those functions that your application requires, and only those functions. So if you use only a small number of IPP functions this is probably the most efficient way to build and load your application. The functions you call are bound directly into your application.

When youlink with the dynamic library, the DLL containsALL the functions associated with the domain. In other words, if you only use 6 IPP functions, all in a single domain, but the domain includes 400 functions, then all 400 functions must be loaded into memory. Obviously, there will be more overhead associated with the initial load of the DLL into memory, and a greater likelihood that some parts of the DLL maybe swapped to disk as the result of changing system memoryand task priorities.

Virtual memory needs, disk performance, size of your application and the associated libraries relative to the amount of free memory, number and types of other processes on the system all contribute to delays in load and run times of your application.

Unfortunately, there is no simple answer. In general, you should get better performance from static linking, but there is no guarantee and the final result depends on your application and your system.

View solution in original post

0 Kudos
5 Replies
Ying_H_Intel
Employee
642 Views
Hello,

According to yourdiscriptions, itseems be caused by the overhead of loading dynamic libraries at runtime. as the article mentioned, http://software.intel.com/en-us/articles/performance-slow-down-when-dynamically-linking-with-intel-mkl/

But it may be caused by other reasons,whichdepends onyour problem. For example,some discussion in the forum:
IPP6.1 DLL loading time on XP with VC8
RSS Feed (read-only)LIB vs. DLL
More detials or a test codeto reproducethe behaviouswould be helpful

Kind Regards,
Ying
0 Kudos
vetroxl
Beginner
642 Views
Hi Ying,
Thanks for the reply. I tested further, here is what I did;
1. I removed linking the libs that are not being used
2. I rebooted my machine
3. I ran my app, it worked ~2.9ms time
4. I shut down the app, no errors.
5. I relaunched the app and was back to ~4ms time
6. I repeated steps 2-5 with the same results.
If i do the steps 3-5, I keep the 2.9ms time when I'm in a static lib. I'm confused as to which linkage I should be using... or is this a heapcorruptionwhen using a dll? But I don't understand why it would mess up in the second launch?!
Thanks.
0 Kudos
vetroxl
Beginner
642 Views
Hi,
I switched to run-time linking of my dll from load-time linking and my performance is back. I am still curiouse why this is?
Thanks
0 Kudos
PaulF_IntelCorp
Employee
643 Views
The reasons for time delays associated with loading a shared library are application and OS dependent, other than the delayed load feature used by the IPP 6.1 library, the libraryhas very little control over this issue. You might want to search the web for detailed articles regarding the pros and cons of linking statically versus dynamically.

When you load a statically-linked application your application EXE includes all of those functions that your application requires, and only those functions. So if you use only a small number of IPP functions this is probably the most efficient way to build and load your application. The functions you call are bound directly into your application.

When youlink with the dynamic library, the DLL containsALL the functions associated with the domain. In other words, if you only use 6 IPP functions, all in a single domain, but the domain includes 400 functions, then all 400 functions must be loaded into memory. Obviously, there will be more overhead associated with the initial load of the DLL into memory, and a greater likelihood that some parts of the DLL maybe swapped to disk as the result of changing system memoryand task priorities.

Virtual memory needs, disk performance, size of your application and the associated libraries relative to the amount of free memory, number and types of other processes on the system all contribute to delays in load and run times of your application.

Unfortunately, there is no simple answer. In general, you should get better performance from static linking, but there is no guarantee and the final result depends on your application and your system.
0 Kudos
vetroxl
Beginner
642 Views
Thanks for your help Paul. I have to research dispatching a little more....
0 Kudos
Reply