How to increase the startup speed of the delphi app?

 ̄綄美尐妖づ 提交于 2019-11-30 11:09:06

问题


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 works?

Note: I'm not talking about fast algorithms or the likes. Only the performance increase at startup, in terms of speed.


回答1:


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.




回答2:


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




回答3:


Well, as Argalatyr suggested I change my comment to a separate answer:

As an extension to the "don't auto create forms" answer (which will be quite effective by itself) I suggest to delay opening connections to databases, internet, COM servers and any peripheral device until you need it first.




回答4:


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.




回答5:


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




回答6:


Fastest code - it's the code, that never runs. Quite obvious, really ;)




回答7:


Deployment of the application can (and usually does!) happen in ways the developer may not have considered. In my experience this generates more performance issues than anyone would want.

A common bottleneck is file access - a configuration file, ini file that is required to launch the application can perform well on a developer machine, but perform abysmally in different deployment situations. Similarly, application logging can impede performance - whether for file access reasons or log file growth.

What I see so often are rich-client applications deployed in a Citrix environment, or on a shared network drive, where the infrastructure team decides that user temporary files or personal files be stored in a location that the application finds issues with, and this leads to performance or stability issues.

Another issue I often see affecting application performance is the method used to import and export data to files. Commonly in Delphi business applications I see export functions that work off DataSets - iterating and writing to file. Consider the method used to write to file, consider memory available, consider that the 'folder' being written to/read from may be local to the machine, or it may be on a remote server.

A developer may argue that these are installation issues, outside the scope of their concern. I usually see many cycles of developer analysis on this sort of issue before it is identified as an 'infrastructure issue'.




回答8:


  • First thing to do is to clear auto created forms list (look for Project Options). Create forms on the fly when needed, especially if the application uses database connection (datamodule) or forms that include heavy use of controls.
  • Consider using form inheritance also to decrease exe size (resource usage is mimized)
  • Decrease number of forms and merge similar or related functionality into single form



回答9:


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.




回答10:


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.




回答11:


This is just for the IDE, but Chris Hesick made a blog posting about increasing startup performance under the debugger.



来源:https://stackoverflow.com/questions/1115421/how-to-increase-the-startup-speed-of-the-delphi-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!