Sign in to follow this  
d000hg

Overhead for calling DLL functions?

Recommended Posts

d000hg    1199
Now this isn't meant to start some crazy war on minute optimisations. I just want to know what difference there is between a normal function/class method call, and calling from the .exe to a .dll? How many such calls would I have to make a second to see any difference -100s, 1000s, millions? I'm thinking it would be nice to have some AI stuff in a dll to save compiling everything when I make a change but there would be a fair load of communication. Is this even an issue or is it like the difference between a normal and inline function (ie nearly always not important)?

Share this post


Link to post
Share on other sites
JohnBolton    1372
The biggest additional cost is the cache miss that is likely when you look up the address of the function. The interesting thing about this is that if you call functions in the DLL often, the likelyhood of a cache miss is much less, and then using a DLL is only slightly more expensive.

On the other hand, DLLs are not easy to use. Why not use a static library? Why does it need to be a DLL?

Share this post


Link to post
Share on other sites
hplus0603    11356
A DLL call on Windows is a call to a dispatch table that jumps to the actual function. This has very similar performance characteristics to a vtable for a polymorphic object, except the virtual function call is done using register-indirect calling, and passing a "this" pointer, so it costs a little more, especially if the data happens to be in the cache (else the cache misses will drown out the instruction cost).

So, in call cost, the ordering is:

Local function call (cheapest)
DLL function call
Virtual function call (most expensive)

To see real differences, you'll need millions of calls a second on a modern computer. The difference shouldn't be huge, especially if the function actually DOES stuff :-) To measure, you can set up a micro-benchmark using RDTSC.

Share this post


Link to post
Share on other sites
d000hg    1199
So the short answer is: don't worry about it? Don't call GetX thousands of times every frame into a DLL but otherwise it's fine?


JohnBolton:Partly just to let me work on stuff like the AI in total isolation. So there is an interface defined for the AI system to get information and then I can just compile a small DLL project when working on the AI. It would also make testing different versions slightly easier if I could run the .exe and specify the name of the DLL. Or even I could ahve each AI 'mind' in a DLL and then I can load the AI I want when a mission starts.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this