project load faster
I am writing my own text editor, and I was wondering how can I make it load faster. Notepad.exe witch comes with windows loads almost instantly and it is a small application (on XP is 67.5KB), I know that my app is a MDI project, but it has ~900KB and it loads in 5 seconds. I could write a DLL with all bitmaps and load them from there but I don't thing that this is the soluti开发者_如何转开发on. Anyone has any ideea?
thanks
In one of my projects I gained a tremendous decrease in loading time by disabling the autocreation of forms. Only the mainform is created in the DPR, all others are created when needed.
Often, it's the perceived speed that's important rather than the actual speed. If you can get a splash screen up as quickly as possible and continue initializing while that's up, people will see that as faster.
Another trick is to put most of your code into DLLs and run your program on Windows startup with a special invisible mode:
myprog.exe /sneaky
which may convince Windows to leave your DLLs in memory so that, next time your application starts, it's faster.
Or even stay running in memory in invisible mode and, when the user runs myprog.exe themselves, simply make yourself visible.
Yet again, use lazy-loading DLLs for the bulk of your functionality (we've used this one under UNIX) so that it's only loaded when needed. This amortizes the loading process over the total execution time rather than taking a big hit at startup.
Those are some tricks I've heard of, there may be others.
All performance problems, can be solved by looking at the code that is executed.
Guessing what is causing the performance problems may have you spinning your wheels for a long time. When you have a performance problem, you need to profile your code. There are various tools for Delphi out there to help you do this.
Some of which are:
- Automated AQTime
- ProDelphi
- Sampling Profiler
These and other options were discussed in this Stack Overflow Question
There are various techniques to speed up code once you have identified what the problem areas are. Since you have identified the area you want to improve, profile the start up of your application.
You may find that your creating things such as forms, resources, or other object that don't need to be created at startup.
Often applications have more than one way they can be started. Since your application is a text editor I suspect you may have a command line where you can specify the file you want to edit. Profiling the different ways you can start your application is key to make sure really know all the impacts of performance improvement.
I noticed that my project loads E_SKU327.dll and E_DAUDF1.dll about 20 times, those files belong to a shared printer (Epson Stylus), so I removed the TPageSetupDialog from my form, and it loads instantly :)
Problem solved :)
Try to omit the code on the start and initializations sections, and see if there's any improvement, then check which section make your application load slower in this case.
and if you testing the startup time with opening text file, try to replace TMEMO (if you are using it) with SynEdit and it will load the text files a lot faster, even from Notepad ;-).
精彩评论