How to increase the startup speed of the delphi app?

前端 未结 11 1952
醉梦人生
醉梦人生 2020-12-24 09:54

What do you do to increase startup speed (or to decrease startup time) of your Delphi app?

Other than application specific, is there a standard trick that always wor

相关标签:
11条回答
  • 2020-12-24 10:33

    Display a splash screen, so people won't notice the long startup times :).

    0 讨论(0)
  • 2020-12-24 10:34

    Compress your executable and any dlls using something like ASPack or UPX. Decompression time is more than made up for by faster load time.

    UPX was used as an example of how to load FireFox faster.

    Note that there are downsides to exe compression.

    0 讨论(0)
  • 2020-12-24 10:35

    Put long running tasks (open database connections, connect to app server, etc) that have to be performed on startup in a thread. Any functionality that depends on these tasks are disabled until the thread is done.

    It's a bit of a cheat, though. The main form comes up right away, but you're only giving the appearance of faster startup time.

    0 讨论(0)
  • 2020-12-24 10:38

    In the project options, don't auto-create all of your forms up front. Create and free them as needed.

    0 讨论(0)
  • 2020-12-24 10:45

    Try doing as little as possible in your main form's OnCreate event. Rather move some initialization to a different method and do it once the form is shown to the user. An indicator that the app is busy with a busy mouse cursor goes a long way.

    Experiments done shows that if you take the exact same application and simply add a startup notification to it, users actually perceive that app as starting up faster!

    Other than that you can do the usual things like exclude debug information and enable optimization in the compiler.

    On top of that, don't auto create all your forms. Create them dynamically as you need them.

    0 讨论(0)
  • 2020-12-24 10:45

    Three things happen before your form is shown:

    1. All 'initialization' blocks in all units are executed in "first seen" order.
    2. All auto-created forms are created (loaded from DFM files and their OnCreate handler is called)
    3. You main form is displayed (OnShow and OnActivate are called).

    As other have pointed out, you should auto-create only small number of forms (especially if they are complicated forms with lots of component) and should not put lengthy processing in OnCreate events of those forms. If, by chance, your main form is very complicated, you should redesign it. One possibility is to split main form into multiple frames which are loaded on demand.

    It's also possible that one of the initialization blocks is taking some time to execute. To verify, put a breakpoint on the first line of your program (main 'begin..end' block in the .dpr file) and start the program. All initialization block will be executed and then the breakpoint will stop the execution.

    In a similar way you can step (F8) over the main program - you'll see how long it takes for each auto-created form to be created.

    0 讨论(0)
提交回复
热议问题