开发者

ways to improve the launch speed of C++ application

Recently, my bos开发者_JAVA技巧s asked me to improve the launch speed of our application, the AP was written with C++. The AP is a little big, it used 200+ dll, Windows needs long time to enter the main() function. I tried these two ways, but still can't make our boss happy.

  1. delay load dll http://msdn.microsoft.com/en-us/library/yx9zd12s(VS.80).aspx
  2. use EDITBIN to to modify EXE http://msdn.microsoft.com/en-us/library/xd3shwhf(VS.80).aspx

Are there other ways to improve it? Thanks in advance.


You need to profile your application in order to determine the true cause of the slowdown. For example, it could be that you are spending most of the time in some initialization routine of one the .dll's you are loading. Go find yourself a good profiling tool and then determine where the bottleneck is.


Jeez! Reduce that DLL count!

Of course, if you're gonna load 200 DLLs on startup, it's gonna incur heaps of hard page faults, and take forever to boot (like 3ds max).

Rethink your DLL strategy. Combine many small DLLs into larger ones. I seriously doubt you need 200+.

And watch Raymond Chen's Five Things Every Win32 Programmer Needs to Know.


A couple of things I guess you need to know:

  • Many small files is way slower then a couple of big files
  • Disk access is much slower then memory access (DLLs need to be loaded from disk)

Reducing the amount of DLLs is a must in this situation. Maybe you can combine then, but I guess it's a modular design, which means, most of the times, they cannot be combined.

You could also load the DLLs on use, instead of on opening of the program and only load the necessary DLLs to load the program on startup.

Or you could even delay the loading of DLLs by first starting the program with the necessary DLLs and then load the others, on order of importance to use.


If you have access to the code of the dlls ( or some of them ) you could look for candiates to staticly link. If you can convert a bunch of them to static libraries, you could speed up the startup dramaticaly.


Use lazy construction of static objects.

Instead of having globals that get created during start-up, like this:

Foo foo;
Bar bar;

int main()
{
    // Access foo and bar
}

Have them constructed on demand with the following idiom:

Foo & foo()
{
    static Foo the_instance;
    return the_instance;
}
Bar & bar()
{
    static Bar the_instance;
    return the_instance;
}

int main()
{
    // Access objects through foo() and bar()
}

This will save you some start-up time if the objects are expensive to create (e.g., have to build up large look-up tables or perform heavy IO).

This will no help with loading those DLL's though.


You're getting good advice here. Having many DLLs is one of those passing fads that you are now paying for. In addition, initializing them may be doing a lot more than you need.

There's a simple way to tell what's taking the time. Start the app under an IDE, such as Visual Studio, and while it's starting up, hit the "Pause" button and display the call stack. Do this several times. Each time, you will see what it is doing and, most importantly, why. If you see that it is spending much time doing something that you don't really need, then that tells you what to fix.


One option, and its pure mind games, is to provide a progress bar on load...

If people have something to look at it distracts them and makes it "feel" quicker, that's why there are mirrors between elevators that serve numerous floors...

This won't beat a stopwatch though...

The other alternative is to re-write it to use less DLLs. How much of a budget (money/time) you have is the next question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜