views:

227

answers:

6

Would I expect to see any performance gain by building my native C++ Client and Server into 64 bit code?

What sort of applications benefit from having a 64 bit specific build?

I'd imagine anything that makes extensive use of long would benefit, or any application that needs a huge amount of memory (i.e. more than 2Gb), but I'm not sure what else.

+1  A: 

Not much else, really. Though writing a 64-bit app can have some advantages to you, as the programmer, in some cases. A simplistic example is an application whose primary focus is interacting with the registry. As a 32-bit process, your app would not have access to large swaths of the registry on 64-bit systems.

DannySmurf
A: 

According to this web page you benefit most from the extra general-purpose registers with 64 bit CPU if you use a lot of and/or deep loops.

OIS
A: 

You can expect gain thanks to the additional registers and the new passing parameters convention (which are really linked to the additional registers).

Edouard A.
+1  A: 

Before working too hard on figuring out whether there is a technical case for the 64-bit build, you must verify that there is a business case. Are your customers asking for such a build? Will it give you a definitive leg up in competition with other vendors? What is the cost for creating such a build and what business costs will be incurred by adding another item to your accounting, sales and marketing processes?

While I recognize that you need to understand the potential for performance improvements before you can get a handle on competitive advantages, I'd strongly suggest that you approach the problem from the big picture perspective. If you are a small or solo business, you owe it to yourself to do the appropriate due diligence. If you work for a larger organization, your superiors will greatly appreciate the effort you put into thinking about these questions (or will consider the whole issue just geeky excess if you seem unprepared to answer them).

With all of that said, my overall technical response would be that the vast majority of user-facing apps will see no advantage from a 64-bit build. Think about it: how much of the performance problems in your current app comes from being processor-bound (or RAM-access bound)? Is there a performance problem in your current app? (If not, you probably shouldn't be asking this question.)

If it is a Client/Server app, my bet is that network latency contributes far more to the performance on the client side (especially if your queries typically return a lot of data). Assuming that this is a database app, how much of your performance profile is due to disk latency times on the server? If you think about the entire constellation of factors that affect performance, you'll get a better handle on whether your specific app would benefit from a 64-bit upgrade and, if so, whether you need to upgrade both sides or whether all of your benefit would derive just from the server-side upgrade.

Mark Brittingham
A: 

Continuing @mdbritt's comment, building for 64-bit makes far more sense [currently] if it's a server build, or if you're distributing to Linux users.

It seems that far more Windows workstations are still 32-bit, and there may not be a large customer base for a new build.

On the other hand, many server installs are 64-bit now: RHEL, Windows, SLES, etc. NOT building for them would be cutting-off a lot of potential usage, in my opinion.

Desktop Linux users are also likely to be running the 64-bit versions of their favorite distro (most likely Ubuntu, SuSE, or Fedora).

The main obvious benefit of building for 64-bit, however, is that you get around the 3GB barrier for memory usage.

warren
Good points, although remember that 32-bit code can still run on 64-bit Windows using WoW64, so 32-bit software doesn't rule out being installed on those OSs
John Sibly
On windows, the default memory limit is actually 2GB pr process and if you work in .NET land (I don't know about unmanaged code) the practical limit is around 1.5GB due to the framework itself taking up a rather large amount of memory.
Morten Christiansen
good point @Morten.. I hadn't seen any OS-specific info in the question, so went with the non-specific answer :)
warren
and @John - if you install the 32-bit libs on Linux, you can likewise run 32-bit code
warren
+6  A: 

Architectural benefits of Intel x64 vs. x86

  • larger address space
  • a richer register set
  • can link against external libraries or load plugins that are 64-bit

Architectural downside of x64 mode

  • all pointers (and thus many instructions too) take up 2x the memory, cutting the effective processor cache size in half in the worst case
  • cannot link against external libraries or load plugins that are 32-bit

In applications I've written, I've sometimes seen big speedups (30%) and sometimes seen big slowdowns (> 2x) when switching to 64-bit. The big speedups have happened in number crunching / video processing applications where I was register-bound.

The only big slowdown I've seen in my own code when converting to 64-bit is from a massive pointer-chasing application where one compiler made some really bad "optimizations". Another compiler generated code where the performance difference was negligible.

Benefit of porting now

Writing 64-bit-compatible code isn't that hard 99% of the time, once you know what to watch out for. Mostly, it boils down to using size_t and ptrdiff_t instead of int when referring to memory addresses (I'm assuming C/C++ code here). It can be a pain to convert a lot of code that wasn't written to be 64-bit-aware.

Even if it doesn't make sense to make a 64-bit build for your application (it probably doesn't), it's worth the time to learn what it would take to make the build so that at least all new code and future refactorings will be 64-bit-compatible.

Mr Fooz
can you tell which were the 'good' and 'bad' compilers?
Javier
Great answer-thanks!
John Sibly
One was Visual Studio, the other GCC. I actually don't remember which was good and which was bad. It was enough of a problem that I had to switch algorithms. In case you're curious, it was a Markov Random Field (MRF) solver and I switched from a graph cuts algorithm to Gibbs sampling.
Mr Fooz