I recently wrote a pair of at least slightly controversial articles about 64-bit vs. 32-bit applications and the performance costs associated with going to 64 bit.
Some people thought I was nuts.
Some people provided benchmarks "proving" that 64 bit code is in fact faster than 32 bit code.
I guess the lesson for me here is that I can't say often enough that I only ever write approximately correct blog entries and YMMV should be stamped on top of everything.
But, just so you don't think I've lost my mind, here is some data.
These are recent builds of IE and Edge in 32 bit and 64 bit. Its the same code, or as close as possible to the same code. This is just the main engine of both plus the old script engine and the new script engine.32 bits 64 bits Growth edgehtml.dll 18,652,160 22,823,936 22.4% mshtml.dll 19,322,880 24,577,536 27.2% chakra.dll 5,664,256 7,830,016 38.2% jscript9.dll 3,667,968 4,895,232 33.5%
This result is completely typical -- between 1.2 and 1.4x growth is very normal for mainstream code. This is not universal, but it's in line with what I've seen elsewhere.
Yes there are exceptions. Yes it totally depends on the codebase.
Now is this going to be slower? Almost certainly because bigger is slower.
Well, if the code has really good locality (e.g. you only use a tiny slice of it; e.g. you move from one well used slice to another well used slice) then it might be that the parts of the code that are hot at any given moment are still fitting well into the cache. But that's sort of a lie as well. You see in a real system there is pollution because device drivers are running and background processes are running and so it's never really the case that there is surplus cache capacity. In real systems extra cache capacity basically just creates the opportunity for your code to remain efficient in the presence of other normal workloads. Micro-benchmarks don't these effects.
I also said that the data is always bigger. People disagree, but there really is no room for disagreement here. I think we can all agree that going to 64 bits won't make your data smaller, so the best you can hope for is a tie. I also think you are going to have at least one pointer on the stack somewhere. So a tie isn't possible. Pedantic yes, but on point. The truth is that depending on your workload you will see varying amounts of growth and no shrinkage. If your growth is sufficiently small, or the locality of the data is sufficiently good, then the extra cache misses from size growth will not be so bad. Micro-benchmarks will often still fit in the cache on a 64 bit system.
Visual Studio is in a poor position viz data growth because it has a lot of pointer rich data structures. Microsoft Edge, Chrome, and Firefox are in relatively better positions because much of their data is not rich in pointers -- bitmaps for instance are essentially (minus some metadata) identical, strings are identical, styles can be stored densely. As a consequence browsers will suffer less than VS would.
The bottom line is that this will vary a great deal based on your workload. But the price of cache misses should not be underestimated. A modern processor might retire over 200 instructions in the same time as one cache miss. More in extreme situations. That's a lot to recover from, extra registers won't do it universally.
I wrote about these phenomena in greater detail in this article from 2014. That article includes a quantitative examination of data growth and locality effects.
I had some top level observations for anyone contemplating a port:
* if you think you're going to get free speed, you have it backwards -- you start in the hole, you will have to win back your losses with processor features, definitely possible but not a given
* if you're going to 64 bits because you're out of memory but you could fix your memory problems with "let's not do this stupid thing anymore" then you should do that
* if you're avoiding 64 bits because you keep saying "I can stay in 32 bits if I do this new stupid thing" then you're kidding yourself, crazy workarounds are doomed
Visual Studio in 2009 was definitely in the situation whereby avoiding some dumb stuff we could make it fit. I don't know where it is in 2016.
This also excludes collateral benefits you get from going to 64 bits, such as avoiding the wow subsystem, cleaning up an otherwise potentially clumsy architecture, greater security due to increased exploit difficulty. Some of these benefits may be very important to your workload/customers.
[I don't have to go out on a limb to acknowledge that is the worst article I've ever written. I wrote it in the wee hours one morning in a rotten mood and it shows. There are far too many absolutes that should have been qualified and the writing style is too aggressive for no good reason. I'm not taking it down because there are worthy comments, and I refuse to try to pretend it never happened. But I absolutely regret writing this article in this way. If you choose to read this, use a large sanity filter and look at some of the comments and the follow-up for qualifications to help see what I'm getting at.]
[This article is in response to an earlier posting which you can find here]
I’ve been reading some of the commentary on my post about 64-bit Visual Studio which is really about 64-bit vs. 32-bit generally using Visual Studio as an example and I have to say that for the most part, I’m pretty disappointed with the arguments being put forth in favor of 64-bits.
[Some less than charitable and totally unnecessary text removed. I blame myself for writing this at 2:30am. It was supposed to be humorous but it wasn't.]
There is an argument to be made here, but there is also a great deal of ignoring of the real issue going on here.
Let’s actually go about doing the job of properly attacking my position the way I think it should be attacked, shall we?
I start with some incontrovertible facts. Don’t waste your time trying to refute them, you can’t refute facts. You can have your own opinion, but can’t have your own facts.
The relevant facts are these:
-the same algorithm coded in 64-bits is bigger than it would be coded in 32-bits
-the same data coded for 64-bits is bigger than it would be coded in 32-bits
-when you run the same code, but bigger encoding, over the same data, but bigger encoding, on the same processor, things go slower
-any work I can possibly do has an opportunity cost which will mean there is some other work I can’t do
All righty, it’s hard to argue with those.
Now let’s talk about the basis I use for evaluation.
-I get points for creating a great customer experience
-I get no points for using technology X, only for the experience, using fewer technologies for the same experience is better than using more
-I get no points for using more memory, not even enabling the use of more memory, only for the experience, using less memory for the same experience is better than using more
OK, so in short, I begin with “64-bits gets no free inherent value, it has to justify itself with Actual Benefits like everything else.”
We cannot make a compelling argument with fallacies like “32 bits was better than 16 therefore 64 must be better than 32”, nor will we get anywhere with “you’re obviously a short-sighted moron.”
But maybe there is something to learn from the past, and what’s happened over the last 6 years since I first started writing about this.
For Visual Studio in particular, it has been the case since ~2008 that you could create VS extensions that were 64-bits and integrate them into VS such that your extension could use as much memory as it wanted to (Multi-process, hybrid-process VS has been a thing for a long time). You would think that would silence any objections right there -- anyone who benefits from 64-bits can be 64-bits and anyone who doesn’t need 64-bits can stay 32-bits. It’s perfect, right?
Well, actually things are subtler than that.
I could try to make the case that the fact that there are so few 64-bit extensions to VS is proof positive that they just aren’t needed. After all, it’s been nearly 8 years, there should be an abundance of them. There isn’t an abundance, so, obviously, they’re not that good, because capitalism.
Well, actually, I think that argument has it exactly backwards, and leads to the undoing of the points I made in the first place.
The argument is that perhaps it’s just too darn hard to write the hybrid extensions. And likewise, perhaps it’s too darn hard to write “good” extensions in 32-bits that use memory smartly and page mostly from the disk. Or maybe not even hard but let’s say inefficient –from either an opportunity cost perspective or from a processor efficiency perspective; and here an analogy to the 16-bit to 32-bit transition might prove useful.
It was certainly the case that with a big disk and swappable memory sections any program you could write in 32-bit addressing could have been created in 16-bit (especially that crazy x86 segment stuff). But would you get good code if you did so? And would you experience extraordinary engineering costs doing so? Were you basically fighting your hardware most of the time trying to get it to do meaningful stuff? It was certainly that case that people came up with really cool ways to solve some problems very economically because they had memory pressure and economic motivation to do so. Those were great inventions. But at some point it got kind of crazy. The kind of 16-bit code you had to write to get the job done was just plain ugly.
And here’s where my assumptions break down. In those cases, it’s *not* the same code. The 16-bit code was slow ugly crapola working around memory limits in horrible ways and the 32-bit code was nice and clean and directly did what it needed to do with a superior algorithm. Because of this, the observation that the same code runs slower when it’s encoded bigger was irrelevant. It wasn’t the same code! And we all know that a superior algorithm that uses more memory can (and often does) outperform an inferior algorithm that’s more economical in terms of memory or code size.
Do we have a dearth of 64-bit extensions because it’s too hard to write them in the hybrid model?
Would we actually gain performance because we wouldn’t have to waste time writing tricky algorithms to squeeze every byte into our 4G address space?
I don’t have the answer to those questions. In 2009 my thinking was that for the foreseeable future, the opportunity cost of going to 64-bits was too high compared to the inherent benefits. Now it’s 2016, not quite 7 years since I first came to that conclusion. Is that still the case?
Even in 2009 I wanted to start investing in creating a portable 64-bit shell* for VS because I figured the costs would tip at some point.
I don’t work on Visual Studio now, I don’t know what they’re thinking about all this.
If there’s a reason to make the change now, I think I’ve outlined it above.
What I can say is that even in 2016, the choice doesn’t look obvious to me. The case for economy is still strong. And few extensions are doing unnatural things because of their instruction set – smart/economical use of memory is not unnatural. It’s just smart.
*the "Shell" is the name we give to the core of VS (what you get with no extensions, which is nearly nothing, plus those few extensions that are so indispensable that you can't even call it VS if you don't have them, like solutions support -- that's an extension]
The topic of 64-bit Visual Studio came up again in a tweet and, as usual, I held my ground on why it is the way it is. Pretty predictable. But it’s not really possible to answer questions about your position in a tweet, hence this posting. I’m going to make some generalizations to make a point and you should really not use those generalizations to make specific conclusions about specific situations. This is as usual in the spirit of giving approximately correct advice rather than writing a novel. Let’s say I convert some program to a 64-bit instruction set from a 32-bit instruction set. Even without knowing anything about the program I can say with pretty good confidence that the most probable thing that will happen that it will get bigger and slower. “But Rico! More RAM better! More bits better!” In the immortal words of Sherman T. Potter: “Horse hucky!” I’ve said this many times before, for the most part there is no space/speed trade-off. Smaller IS Faster. In fact, in a very real sense Space is King. Or if you like Bigger is Slower. Part of the reason we study space/speed tradeoffs is because they are exotic beasts and it’s important to understand how it is that using more memory, inherently more expensive, can strangely give you a speedup, and under what conditions that speedup actually persists. Let’s break it down to two cases: 1. Your code and data already fits into a 32-bit address space Your pointers will get bigger; your alignment boundaries get bigger; your data is less dense; equivalent code is bigger. You will fit less useful information into one cache line, code and data, and you will therefore take more cache misses. Everything, but everything, will suffer. Your processor's cache did not get bigger. Even other programs on your system that have nothing to do with the code you’re running will suffer. And you didn’t need the extra memory anyway. So you got nothing. Yay for speed-brakes. 2. Your code and data don’t fit into a 32-bit address space So, you’re now out of address space. There are two ways you could try to address this. a) Think carefully about your data representation and encode it in a more compact fashion b) Allow the program to just use more memory I’m the performance guy so of course I’m going to recommend that first option. Why would I do this? Because virtually invariably the reason that programs are running out of memory is that they have chosen a strategy that requires huge amounts of data to be resident in order for them to work properly. Most of the time this is a fundamentally poor choice in the first place. Remember good locality gives you speed and big data structures are slow. They were slow even when they fit in memory, because less of them fits in cache. They aren’t getting any faster by getting bigger, they’re getting slower. Good data design includes affordances for the kinds of searches/updates that have to be done and makes it so that in general only a tiny fraction of the data actually needs to be resident to perform those operations. This happens all the time in basically every scalable system you ever encounter. Naturally I would want people to do this. Note: This does NOT mean “store it in a file and read it all from there.” It means “store *most* of it in a file and make it so that you don’t read the out-of-memory parts at all!” This approach is better for customers; they can do more with less. And it’s better for the overall scalability of whatever application is in question. In 1989 the source browser database for Excel was about 24M. The in-memory store for it was 12k. The most I could justify on a 640k PC. It was blazing fast because it had a great seek, read and cache story. The big trouble with (b) is that Wirth’s Law that “software manages to outgrow hardware in size and sluggishness” applies basically universally and if you don’t push hard nothing ever gets better. Even data that has no business being as big as it is will not be economized. Remember, making it so that less data needs to be accessed to get the job done helps everyone in all the cases, not just the big ones. So what does this have to do with say Visual Studio? * I wrote about converting VS to 64-bit in 2009 and I expect the reasons for not doing it then mostly still apply now. Most of Visual Studio does not need and would not benefit from more than 4G of memory. Any packages that really need that much memory could be built in their own 64-bit process and seamlessly integrated into VS without putting a tax on the rest. This was possible in VS 2008, maybe sooner. Dragging all of VS kicking and screaming into the 64-bit world just doesn’t make a lot of sense. ** Now if you have a package that needs >4G of data *and* you also have a data access model that requires a super chatty interface to that data going on at all times, such that say SendMessage for instance isn’t going to do the job for you, then I think maybe rethinking your storage model could provide huge benefits. In the VS space there are huge offenders. My favorite to complain about are the language services, which notoriously load huge amounts of data about my whole solution so as to provide Intellisense about a tiny fraction of it. That doesn’t seem to have changed since 2010. I used to admonish people in the VS org to think about solutions with say 10k projects (which exist) or 50k files (which exist) and consider how the system was supposed to work in the face of that. Loading it all into RAM seems not very appropriate to me. But if you really, no kidding around, have storage that can’t be economized and must be resident then put it in a 64-bit package that’s out of process. That’s your best bet anyway. But really, the likelihood that anyone will have enough RAM for those huge solutions even on a huge system is pretty low. The all-RAM plan doesn’t scale well… And you can forget about cache locality. There’s other problems with going 64 bit. The law of unintended consequences. There’s no upper limit on the amount of memory you can leak. Any badly behaved extension can use crazy amounts of memory, to the point where your whole system is unusable. *** But, in general, using less memory is always better advice than using more. Creating data structures with great density and locality is always better than “my representation is a n-way tree with pointers to everything everywhere” My admonition for many years has been this: Think about how you would store your data if it were in a relational database. Then do slices of that in RAM. Chances are you’ll end up in a much better place than the forest of pointers you would have used had you gone with the usual practice. Less pointers, more values. This isn’t about not wanting a great experience for customers, nothing could be further from the truth. It’s about advocating excellence in engineering rather than just rubberstamping growth. This is basically my “brand.” * I don't work on Visual Studio anymore, don't read this as any indication of future plans or lack of plans because I literally have no idea ** there are significant security benefits going to 64-bit due to address randomization and you do get some code savings because you don’t need the WOW subsystem, but VS is so big compared to those libraries that doesn’t really help much, it was a big factor for MS Edge though *** Also happens in MS Edge