.Net 4.0 is 64 bit slower than 32 bit (profiling and possible solutions) (application uses NetAdvantage)

We have a .NET application written in VB.NET 4.0 / VS2010, compiled with all projects installed in AnyCPU settings for Debug and Release configuration. We noticed that when this application runs in a 64-bit environment (tested on Windows Server 2003 R2 and 2008 R2), the application then takes at least twice as much (in absolute terms about 25 seconds), and not about 6-12 seconds in 32-bit environment (Win XP and 7) to run.

I must add that 64-bit systems are powerful servers, definitely more powerful than other 32-bit systems under test. All other applications were faster on 64-bit, but not on our poor application;) (And we tested the applications at different times, under different loads, and the results are always almost the same.)

As mentioned above, the application is built using AnyCPU and works as a 64-bit build under a 64-bit OS (checked through the TaskManager). The application itself is a WinForms application using NetAdvantage Forms v10.3 and regularly querying and writing to MS SQL Server 2008.

Different target computers are on the same network, so the database path (the same database was used for performance tests), for example, is the same, I don’t think the problem is with the database or the network itself.

One thing that I noticed, which seemed strange to me, was that when I built different “profiling steps” using a stopwatch while starting our MainForm, the InitializeComponent method took twice as much by 64 bits, about 4 seconds versus 1 , 5 by 32 bits.

This is the same application that we deploy on both systems, without a different configuration.

So, I have two questions:

Any idea what could be the reason for this?

And: What is the best way to identify “offensive” code snippets? I am currently using stopwatch and trying to narrow it down. But it seems to me that on 64-bit machines everything is slower than our application, so I'm not sure that I can break it down into specific statements.

Thank you all for your help, really appreciate ...

+7
source share
3 answers

It turned out that as soon as we switched from compiling from AnyCPU to a specific x86, that is, we also launched x86 on the x64 bit platform, we returned to our "good speed".

+4
source

Had the same problem - and yes, JIT is to blame. Reasonably using msgbox, narrowed it down to a method that would run 10 seconds (by calling a message box before calling a large method, and then as the first line of a large function.) And yes, I only saw this when compiling as AnyCPU, but not explicitly x86 ; not when debugging.

In my case, it was 5000 lines of Windows Forms InitializeComponent .

To prove this, run (upgraded) " c:\windows\<.net framework dir>\ngen.exe install <myassembly.exe> ", which will compile your own image. If this is fixed, then yes, the JIT was to blame.

Long-term fixes:

  • use ngen every time you deploy a program to restore your own image (or update ngen to recreate, but it obviously only works once after installation); (Downside manages ngen images and the time it takes for ngen. This is the route I took because there is a general performance gain for larger applications.)

  • or you can add the <System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.NoOptimization)> attribute to the method. (Disables JIT in the method, so it works slower, but you don’t pay the initial overhead of JITing, which is an expensive part for us)

(I suspect that doing both is inconclusive, since that would mean giving up my own image of a large method without amplification).

+4
source

I recently had the same issue with application performance. And yes, compiling it as x86 solved the problem; then he quickly advanced on any platform. But the real reason for the slow start-up response time is due to migration problems from 32 to 64 bits. I think that when the application starts and it goes through the JIT process to turn the code into IL, the compiler determines that there are problems in the code (for example, un-type safe code) that it must solve before it can run in 64 bit mode. I came across this article and now I am trying to go through the application to determine which ones are causing problems. See this article: http://msdn.microsoft.com/en-us/library/ms973190.aspx . I can leave it alone as it works, but ideally it will work better in 64-bit mode if the problems are fixed.

+2
source

All Articles