Search code examples
wpfperformance

WPF Load Slow application on cold start, many modules?


Good morning.

I wanted to expose the problem that I have, when running my application on a cold boot (right when restarting the pc) on certain machines it becomes slow so that the main application screen appears, like 12 seconds.

Then the second time you start it, it works fine.

More data: - WPF application desktop windows in C #.

  • When running the application the splash screen appears instantly, and the login windows screen appear in 2-3 seconds (this is acceptable).
  • When you type in screen login the user and password and it is accepted is when it is slow and it takes 12 seconds to appear in the main menu. (In cold start then the next times you go and go normal).

  • So I doubt that it can be, the code does not do anything exceptional:

1.- Could it be a problem in the connection to the local sql database? 2.- Could it be the structure of the solution? I explain, the program is inherited from a partner and is composed of a solution with 5 projects inside.

 - Backend.UI  (where are the visualization forms and functionalities)
 - Business    (where it puts the BLO)
 - Data        (where you put the DAO)
 - Domain      (where it places the entities)
 - Resources  (Resource Files)

Is this structuring correct? Would not it be better to put everything in a single project separate each thing with your folder?

I say it by the following, analyzing with the debug I see that until the first login screen only load:

(CLR v4.0.30319: DefaultDomain): Loaded 'c:\Prueba\xxxx.BackEnd.UI\bin\Debug\xxxx.BackEnd.UI.exe'. Symbols loaded.

And once accepted the login to the main menu (here is when it is slow, 12 seconds) loads the other modules.

(CLR v4.0.30319: xxxx.BackEnd.UI.exe): Loaded 'c:\Prueba\xxxx.BackEnd.UI\bin\Debug\xxxx.Domain.dll'. Symbols loaded.

(CLR v4.0.30319: xxxx.BackEnd.UI.exe): Loaded 'c:\Prueba\xxxx.BackEnd.UI\bin\Debug\xxxx.Business.dll'. Symbols loaded.

(CLR v4.0.30319: xxxx.BackEnd.UI.exe): Loaded 'c:\Prueba\xxxx.BackEnd.UI\bin\Debug\xxxx.Data.dll'. Symbols loaded.

Can this be the problem? That having several projects (which I do not think need to have them separated) have to load them and that takes time ....

Remember that this slowness is only in the first charge after starting the machine, then everything is fine. But 12 seconds I see too much.

Thank you in advance for any comments.


Solution

  • It does take time to load and JIT a .NET project on first start. Multiple libraries might take more time if your hard disk is really, really slow.

    I would guess that with a modern HDD, if you put all your code into one single executable, your program will take the same amount of loading time on a cold start, just once at the start, instead of later, when the library is loaded.

    But you could just try it. Move all your files over to your executable project and test it.

    Generally speaking, the Just-in-time compiler (commonly called Jitter) will compile your IL (Intermediate language) code to native code when you start your program. Through various caches on different levels, this will be faster when you do it more often. As the Jitters strong suit is compiling your IL to exactly the specification of your system, a cold start clears all those caches. After all, a cold start is when you system could really have changed (you could have insterted more RAM, a different processor, etc). So yes, it is normal that it takes longer to start your program the first time.

    If your specific starting time can be optimized is something that only you can check. Use an profiler.