64bit .NET Performance tuning

2019-02-09 00:20发布

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

5条回答
孤傲高冷的网名
2楼-- · 2019-02-09 00:41

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.

查看更多
等我变得足够好
3楼-- · 2019-02-09 00:44

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)

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-09 00:47

Performance bottlenecks will be the same regardless of whether the architecture is 32- or 64-bit. Performance problems tend to be the result of sub-optimal algorithms — the choice between 32- and 64-bit types won't significantly affect performance.

Most importantly, don't try to improve the performance of something before you've measured it. In particular you should profile the code to determine where your performance bottlenecks are.

查看更多
相关推荐>>
5楼-- · 2019-02-09 00:54

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.

查看更多
Ridiculous、
6楼-- · 2019-02-09 00:57

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 when 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.

查看更多
登录 后发表回答