views:

1169

answers:

5

I know that .NET is JIT compiled to the architecture you are running on just before the app runs, but does the JIT compiler optimize for 64bit architecture at all? Is there anything that needs to be done or considered when programming an app that will run on a 64bit system? (i.e. Will using Int64 improve performance and will the JIT compiler automatically make Int64 work on 32bit systems?)

A: 
Ted Percival
+8  A: 

The 64bit JIT is different from the one for 32bit, so I would expect some differences in the output - but I wouldn't switch to 64bit just for that, and I wouldn't expect to gain much speed (if any) in CPU time by switching to 64bit.

You will notice a big performance improvement if your app uses a lot of memory and the PC has enough RAM to keep up with it. I've found that 32bit .NET apps tend to start throwing out of memory exceptions whne you get to around 1.6gb in use, but they start to thrash the disk due to paging long before that - so you end being I/O bound.

Basically, if you're bottleneck is CPU then 64bit is unlikely to help. If your bottleneck is is memory then you should see a big improvement.

Will using Int64 improve performance and will the JIT compiler automatically make Int64 work on 32bit systems

Int64 already works on both 32bit and 64bit systems, but it'll be faster running on 64bit. So if you're mostly number crunching with Int64, running on a 64bit system should help.

The most important thing is to measure your performance.

Wilka
+4  A: 

This is a good article on the subject, by one of the people who worked on the 64 bit JIT. Basically, unless you absolutely need the address space that 64 bit can offer, or need to do 64 bit math, you will likely lose performance. As pointers are larger, cache is effectively halved, for example.

Bill Wert
+3  A: 

I have noticed 64-bit being a lot slower.

As has been stated the 64-bit JIT compiler behaves differently to the x86 JIT compiler. The x86 compiler will take advantage of some optimizations that the x64 one does not.

For example in .NET 3.5 the 32-bit JIT will inline function calls with structs as arguments, but the 64-bit JIT does not.

In production code I have seen x86 builds running as much as 20% faster than x64 builds (with no other changes)

Oliver Hallam
+1  A: 

To sum up, use 64-bit only if

  1. You need the extra memory and there is no way around it.
  2. You program e.g. scientific apps and need the increased math precision

On every other aspect, as of today, the 64-bit compiler in .NET is one step down.

Performance optimizations done in the .NET compilers are a big issue.

Theo Zographos