tags:

views:

219

answers:

8

I understand the major benefits of being able to build a 64-bit application on Mac OS X: more memory available, better performance, etc.

But what if I have an app with modest memory needs and no performance concerns. Let's assume that porting it to 64-bit is simply a matter of changing the build settings. Would making a 64-bit executable available provide any real benefit to my users on Leopard or Snow Leopard?

I know the knee-jerk reaction of many programmers is "Of course you should support 64-bit!", and some power users will scoff and complain if they see your app is not 64-bit, but I am interested in the real benefits/costs.

Some related issues:

  • I could provide a combined Universal 32-and-64-bit application, but would the benefits (if any) justify the larger download size?
  • I could provide separate 32-bit and 64-bit downloads, but would that just confuse users?
+1  A: 

It's worth trying. The 64-bit programming models have more registers, for instance, and might also allow your compiler to generate better instructions, all of which might lead to more performance.

unwind
My app doesn't need more performance, so that doesn't matter, unless a 64-bit app would improve system-wide performance.
Kristopher Johnson
+1  A: 

Since Mac OS X 10.6 is a pure 64 bit OS, it won't have loaded the 32bit libraries unless some 32bit applications needs them.

So if you manage to only use 64 bit applications, then you save some memory since you don't need to load the 32bit versions of the libraries at all.

Joachim Sauer
Don't you need more memory because some types are bigger in an 64bit environment? Like NSInteger...
Georg
@gs compare that with faulting in all of the code for the libraries from libSystem up to AppKit. Which would be larger?
Graham Lee
Mac OS X 10.6 is not a pure 64-bit OS. On most Macs it boots a 32-bit kernel (by default), and some system services are 32-bit, so is iTunes (for example). So I don't think it's possible to avoid loading most of the 32-bit libraries.
karunski
@karunski It is possible - don't confuse the kernel with the frameworks. The main reason the kernel doesn't boot into 64-bit by default is that many 3rd party drivers are not 64-bit ready. But virtually all the system frameworks are 64-bit now, independent of the kernel mode. You can easily run only 64-bit apps and not touch the 32-bit shared libraries. Activity Monitor will show you which app is which.
gavinb
A: 

Generally speaking using 64bit mode results in lower performance, as registers and memory addresses are now twice as wide and therefor take twice as much time to move around. 64bit does allow for more memory to be simultaneously available to the application so if you need to address more then 4GB of user memory at once, going 64bit is probably the way to go (4GB here means 4GB minus how much the kernel space takes, which I'm not sure what it is for OS-X. With Linux its often 1GB).

That being said there is some (though not very large) chance that your software uses some combination of instructions that are easier to optimize under 64bit mode - SIMD is usually a good candidate - in which case you can gain some performance benefits.

Worse - if you write your software in C or similar, going to 64bit would require you to make sure that all the ints and longs you use are correctly 64bit safe. This may or may not be hard to do and possibly require a lot more debug time.

Conclusion: On the face of it, if you don't need the memory and you don't expect to gain performance then I wouldn't worry about it. Even the chance that going 64bit would cause OS-X not to load the 32bit shared libraries is pretty slim.

Edit: The "common knowledge" is that 64bit is better then 32bit as 64 > 32, hence opinions as this one is often frowned upon and likely to be moded down due to unpopularity. I still suggest to check carefully what you gain and what you lose by moving to 64bit, and it is rarely a painless process.

Guss
While I agree that moving immediately to 64bit is almost certainly unnecessary, your first paragraph is riddled with inaccurate statements. Why would it take twice as long to move 64bits around in a 64bit system? *Everything* is 64bits: the registers, memory addresses, and the bus systems.
Corey D
64 bit mode usually ends up with _higher_ performance, because there are more registers available so less heading out to memory for automatics, there is a faster kernel->user memory copy and faster system call dispatch. I marked this down because it's incorrect, not because it's unpopular.
Graham Lee
@Graham: more registers do not necesarilliy means better optimisation - most of the registers 64bit mode adds are 64bit registers which are not useful if your software uses no `long long` variables. The extra performance of the call dispatch is not significant in any way
Guss
@Corey: the system bus is not 64bit for a long time now - its been much wider then that for many years now and 64bit systems have not widened it. 32 bit code has higher memory performance then 64bit code on the same system because if you want to push 16 memory addresses on a 256 bit bus, with 32bit addressing you use 2 cycles and with 64bit addressing you use 4 cycles for the same memory access: twice as slow.
Guss
Of course ther are many inaccuracies here - for example 64bit addressing does not actually use 64 bits - it uses 48 bits, but is padded to 64 bits almost everywhere that counts. If you went an accurate technical discussion then i'd need a lot more space and research time then is normally expected in stackoverlow. Still, the basics re sound.
Guss
Guss, 64-bit registers _are_ useful even if you don't use `long long` vars. Some examples? You can fit a pointer in them, you can fit any smaller type like `u_int32_t` or `char` in them. You could even load two `u_int32_t`s at once in a 64-bit GPR; a technique which has been known since at least the time of the Zilog Z80's HL register if not earlier.
Graham Lee
You are correct about addresses - when your code generates long pointers automatically when compiled in 64bit mode which C programs would not do. shorter variables can fit in larger registers, but only if your compiler allows for this dangerous optimization (how will you handle overflow?) and at least GCC (the default OS-X compiler) does not do this. Packing is even dangerous still.
Guss
A: 

Generally, the best answer is to know your users.

If your users are all primarily on 64bit, then it would be worth the time and effort to convert. If your users are all primarily on 32bit then you would be spending time and effort with negligible reward.

If you have the bandwidth, I would suggest that yes, providing a 64bit executable would be best, because at the very least you are widening your possible audience. If you deliver your application through a website, you could attach monitors to see which packages are downloaded most often. That way you are gaining extra information about your users.

How many users know the difference between 32- and 64-bit? Is monitoring how many people download which one really a measure of the benefit? I suspect that simply giving the choice will cause more confusion and fear among users.
Kristopher Johnson
Well, if you convert to 64bit and they have 32bit, then you've lost them as a customer. If you are that worried about it, you could have a 'default' download of one of them, and have the other one as an option further down on the page. Alternately you could give instructions as to how to determine which one you are. I don't know what kind of users you have (technical or non), but the LAST thing you want is hardware incompatibilites, and you want your users to have the option that fits them with the lowest inconvienience.
The lowest-inconvenience option for everyone is to just provide a 32-bit app. The thrust of my question is whether providing 64-bit in addition to 32-bit provides benefits that is worth the extra inconvenience.
Kristopher Johnson
@devinb: or a single download with a universal binary for all customers could work, too.
Graham Lee
I would say provide both download options and have an "I'm not sure!" link directly beneath them. In terms of the performance considerations, I must admit (as you've probably guessed) that I do not know.
A: 

If it's just a build setting: make both available. 64 bit users will want to use the 64 bit version to save the 32 bit library loading while as 32 bit users won't have the choice.

Malaxeur
I am not sure that (a) users know or care about a 64-bit version, or that (b) those who want it will really benefit from it.
Kristopher Johnson
+3  A: 

If you don't absolutely need the increased address space, then I wouldn't bother with a 64 bit build. The issue here is that although you've gained address space, any pointers you use are now 64 bit, and any aligned data structs may well have increased in size, depending upon the compiler settings. You can end up not being able to fit as much stuff in the cache, and that cache is fixed in size irrespective of the available memory fit. Consequently you may well lose performance. It's a balance between these cache effects and the gain in address space: you really have to do some metrics to see the overall effect. If you're looking at a lot of effort for a 64 bit port, or you don't have humoungous memory requirements, I wouldn't bother.

OTOH, if you're writing the next SQLServer/Oracle, the effort is probably worth it :-)

Bob Moore
Actually the increased address space is not the only difference. For example, in 64 bit mode you have more registers available, as others have pointed out. IMO it is thus a typical case of "try and see what the effects are".
Thomas Lötzer
+4  A: 
  1. Providing a 64-bit build will make the power users happy, and provide you with pre-tested forward-compatibility (just in case something breaks under 64-bit compilation. Sure, "that never happens", but...)

  2. In my experience users don't know whether they're on a 32- or 64-bit platform. If you are going to distribute, I would recommend the combined binary. Yes, it's a larger download, but that doesn't seem to be as much of an issue nowadays as it was in times past.

    Unless your market is people with 56k modems (and it is still a market). In that case, distribute a 32-bit-only version, and mark it "for pre-[whatever] Macs", and keep the 'modern' version a 32/64 combo (under the assumption that people with newer Macs will also have faster connections).

Alex Feinman
+1  A: 

I recommend you provide universal 32-bit and 64-bit binary. This will give you the most flexible option and still be able to take advantage of 10.6 improvements.

The benefits of a 64-bit app are:

  • larger address space
  • take advantage of compiler optimisations for x86_64
  • more efficient Objective-C runtime
  • avoid faulting in the 32-bit frameworks on Snow Leopard

Nowadays, when nearly all the Snow Leopard apps are 64-bit, Apple is advising developers to make their apps 64-bit also. Even if you don't need the extra address space, it will still generally be more efficient overall. They stress the point that you don't want your app to be the only 32-bit app on the system (the startup time would be very slow!). So there are definite benefits of making a 64-bit build.

Work on optimizing the Objective-C runtime for 32-bit has been limited by having to retain ABI compatibility. But with the 64-bit runtime, they were able to come up with a new ABI that is more efficient and faster. So you get all the benefits of performance improvements in your app, and in all the Cocoa frameworks too.

A 32/64 Universal binary is a good idea. Having separate downloads would only confuse your users. You can always zip it to reduce the download size.

Please note that the type of the kernel is independent of the frameworks. There is quite some confusion about this in 10.6, as the kernel boots into 32-bit mode by default. But this is still capable of hosting 64-bit applications and frameworks.

You do not need to be running the 64-bit kernel to run 64-bit applications. Snow Leopard is optimized for 64-bit, and your app needs to be 64-bit to take advantage of that.

The Apple documentation on the topic is well worth reading (and covers myths such as the one above):

gavinb