Running Winforms software is 10 times slower than x64 versus x86

I created the popular Winforms program in C #, which has many GUI widgets, and found that when the target platform is x64, starting up is about 5-10x slower than x86. Under the x64 target, it takes about 5 seconds to start, which negatively affects the user's work. I would like to do it faster.

I also tried with my other program, and also found that the launch time under x64 was double or triple than that of x86.

So, I began to wonder what caused this. My programs use quite a few widgets, so to test the theory, I decided to create a test project with 800 buttons! I set all of them to Visible=False so that the redraw / refresh rate does not mutate the water.

Sample form with 800 buttons

To my surprise, x64 launched LOT slower than the x86 equivalent. Then I moved on to the InitializeComponent(); section InitializeComponent(); and, of course, the x64 version started in about 3.5 seconds. The X86, on the other hand, took only about 0.275 seconds. It's almost 13 times faster!

The .NET Framework 2.0, 3.0, and 3.5 are equally bad. Targeting .NET 4 and 4.5 under x64 is much better by about 0.8 seconds, but it's about 3 times smaller (x86 by about 0.28 seconds), and I want to use .NET 3.5 to increase the user base.

So my question is: what makes the x64 version run so slowly, and how can I make it faster so that it is comparable to the x86 version?

If someone wants to test immediately, I created a zip for the VS 2010 project, which can be downloaded here: http://www.skytopia.com/stuff/64_vs_32bit_Startup_Speed.zip

+7
performance c # x86 64bit winforms
source share
1 answer

This is the JIT value of your 10000 InitializeComponent function.

  • If you measure the time between the call to the InitializeComponent and the execution of its first line, this is most of the cost. (Just insert the line at the top of the InitializeComponent to measure.)

  • If you use VS Performance Analyzer, it will display more time spent in ThePreStub , which is associated with JIT.

  • A 64-bit JITter takes longer to compile code than a 32-bit JITter, but in return it gives better code.

    Microsoft is working on a new version of JITter called RyuJIT. It is derived from a 32-bit JITter and has similar characteristics (fast compilation outputting the worst code). It will become the standard JIT in future versions of .NET.

  • .NET 4.5 reduces the cost from 2.0 seconds to 1.3 on my machine. This is likely due to an improvement in JIT in runtime 4.0.

  • An equivalent loop is much faster than your InitializeComponent function.

    This will not help you if you want to create all the components in the designer, but if you have a combination of repeating controls and the components you want to edit in the designer, you can use a loop. Just put it in Form1.cs not in Form1.designer.cs so that it is not overwritten by the constructor.

  • Using NGen on your assembly should eliminate the cost of JIT. But this is due to the lack of the need to deal with the GAC.

+6
source share

All Articles