tags:

views:

88

answers:

3

As the title says, compared to a normal function, is there a perf hit in calling dll functions? The dll will be loaded by dlopen. EDIT: Ignore dlsym time because I only do it once per each function.

A: 

Yes there is a performance hit. You do a dlsym call to get the function's address and then call the function with that address. As there is an added dlsym call compared to a function call from the same module, it must be slower. How much that matters? It depends. The only sure way to know is to measure it.

usta
You are right. But in my case, I only do `dlsym` once for the lifetime of the program for each function. And, additionally I use function pointers to invoke the function. What about then?
nakiya
@nakiya In that case you only lose the opportunities of optimization you'd otherwise have if the called function was linked statically, i.e. inlining, inter-procedural optimization, constant propagation and the like. In other words it's really no different from calling a function of the same module through a function pointer.
usta
A: 

The best way to find out is simply to measure...

ronag
+5  A: 

Calls to DLL functions are indirect by address and the compiler can't inline them, so there is a slight performance hit.

You should only worry if you use them in a performance critical inner loop and after profiling them.

Axel Gneiting
Ok. Profile it is I'll do! :D
nakiya