Sign in to follow this  

are there performance differences between static libs and DLL's?

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I'm finally at that point with my 2D renderer that I'm satisfied with all it's features and wanted to start thinking about making it faster. It's all in a static lib so I was wandering would taking the trouble to implement it in a DLL instead result in greater performance?

Share this post


Link to post
Share on other sites
First of all... actually, no. First of all, Have you profiled your renderer yet to determine where the bottlenecks are? Trying to optimize without profiling first is a little bit like painting racing stripes on your car to make it go faster. Second of all, no it won't.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
First of all... actually, no. First of all, Have you profiled your renderer yet to determine where the bottlenecks are? Trying to optimize without profiling first is a little bit like painting racing stripes on your car to make it go faster. Second of all, no it won't.


thank you, and yes, I have been setting my profiler up into the renderer all day, but am still setting up a few test apps, to test different situations. I was just looking for the one answer for now, ill bug ya later with millions of questions on how to be optomize the rest.

Share this post


Link to post
Share on other sites
It may actually depend on the function itself and the linker you're using. If a specific function gets called a lot of times (when I mean a lot, I mean a LOT), the function call overhead may kill performance (however, it's no different compared to calling a function in your program). Linking statically MAY cause your linker to inline some function calls in your code, eliminating the overhead.

In anycase, if you're calling a function a lot of times (i.e. Texture::setPoint( x, y, color ) ), you're better off batching them which has a better chance of improving performance.

Share this post


Link to post
Share on other sites
DLL's are more of a construction feature than an optimization avenue in my experience. They allow you to construct robust, componentized and maintainable solutions - not faster ones.

If you're only interested in performance then I would put money on there being other more beneficial routes to explore.

btw, moved to 'General Programming' as I don't see this as being a DX-specific issue/question.


Cheers,
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
If anything moving it to a DLL would make it, in the worst case scenario, neglectfully slower, in the best case scenario, there wont be any improvement or degradation


In my case, using DLL (the MVS run-time) sped the application up, since it severely reduced code size.

Yes, there is a performance difference. But which way, where and how will depend on individual application.

DLL is used for dynamic linking purposes. If you need that - you will use it. If you don't, profile, and see how it works out. But there should be no particular extra cost associated with it from code perspective itself.

Share this post


Link to post
Share on other sites
Quote:
Original post by SnT2k
It may actually depend on the function itself and the linker you're using. If a specific function gets called a lot of times (when I mean a lot, I mean a LOT), the function call overhead may kill performance (however, it's no different compared to calling a function in your program). Linking statically MAY cause your linker to inline some function calls in your code, eliminating the overhead.

In anycase, if you're calling a function a lot of times (i.e. Texture::setPoint( x, y, color ) ), you're better off batching them which has a better chance of improving performance.


Yes, this is something to keep in mind. Your compiler/linker may decide to inline functions even if you did not explicitly mark function "inline". And modern compilers are able to inline functions at link-time from static libs. A DLL makes this impossible.
But, as SnT2k said, this will only be an issue if you have a LOT of calls made to the DLL that would otherwise be inlined.

Share this post


Link to post
Share on other sites
The question is more "why are you asking this question?" than anything else (no offense intended). I guess that somebody either asked you the question or told you that one of theses is faster than the other one. There is no trivial answer to it, except this one: are you sure it really matters?

DLLs and static libraries are fundamentally the same thing. There are a few catches that you must be aware of (DLLs functions are called using an indirection table (rough cost: a jmp instruction (that's one or 2 clock cycles IIRC), they are very likely to be placed in a different memory page, which would lead to less efficient code cache management and so on) but on the other hand they also have some nice properties - they can reduce the code size, which might lead to a better code cache management.

So in the end, not only one cannot answer this question in the general way, but it may also question the question itself: since no generalities can be made, is the question that interesting? It shows an interest in mastering application performance, but does it do it in the right way? Instead of focusing on this particular problem, shouldn't one focus on the real performance problems in an application? (algorithm enhancement, implementation improvements and so on). Bad algorithms and implementation are responsible for 99% of your speed problems - while other, more obscure micro-optimizations will only give you 1% benefits.

For my part, I consider that while the question is interesting (it's quite a good question in fact) the answer is not really relevant. If profiling shows any difference between the two methods then you can make a choice (but be aware that any major change in the project might change the result of the profiling). If profiling don't show any real difference, chose the one that will allow you to manage your project.

Best regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
DLLs functions are called using an indirection table (rough cost: a jmp instruction (that's one or 2 clock cycles IIRC)

You'll have to forgive me for the nitpick, but for the sake of accuracy this isn't strictly true.

DLL functions are necessarily a level of indirection further away than statically linked functions, but only due to the IAT (import address table), which results in a CALL DWORD PTR[<IAT Entry>]. The JMP table you speak of is created by many compilers for the sake of edit-and-continue and suchlike. By directing all function calls through a JMP table, it's relatively simple for the debugger to compile a new function ad-hoc and reassign the jump. Some compilers have taken to leaving this table in for release builds, for reasons I'm uncertain of. Anyway, such JMP tables may be found in dynamic and static libraries alike, so it's not fair to give DLLs the blame [rolleyes].

But that's besides the point. Emmanuel and Sneftel speak the truth. It's good to hear that the OP is busy profiling and not painting go-faster stripes.

Admiral

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
The question is more "why are you asking this question?" than anything else (no offense intended). I guess that somebody either asked you the question or told you that one of theses is faster than the other one. There is no trivial answer to it, except this one: are you sure it really matters?


Well the answer to that is quite simple... a combonation of ADD and Boredom. After coding for 2 hours with no break my mind tends to wander off on strange questions like these, that make so much more sense at the moment then they do the next day.

Share this post


Link to post
Share on other sites

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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