Thursday, August 24, 2006

Throwing RAM at XCode Linking

In my day job, I spend a lot of time compiling and linking a fairly large commercial C++ application. My PowerBook G4 was not up to the task of compiling the whole thing in a reasonable time, although I could distribute the compilation to two G5 desktops when I was at work. But this did not help when I worked from home, nor did it help with linking. And no, zero-link never seems to work for me.


So I bought a MacBook, and home compiles are now peppy. But linking is still fairly slow, especially if I'm running my normal selection of apps, and I rarely compile the whole application, but I have to re-link it every time I want to test a change. I ran the Utility Monitor utility while linking and I was shocked to see that linking, which drags my whole computer down to a crawl, was only using 10% of the CPU; it was crawling because even in 1GB of RAM, linking caused a horrible virtual memory paging thrash. Well, one of the nice things about a MacBook is it is upgradeable to 2GB.


I first measured my linking speed on my 1GB 1.83GHz MacBook with a 5400 rpm SATA 120GB Momentus hard drive. It actually wasn't too bad, linking my work application in an average of 150 seconds. If it was like that all the time, I might not have seen the need to upgrade my memory, but adding applications running concurrently makes linking time progressively worse. Launching Safari, iTunes, and iPhoto and doing light browsing while the link completes, bumps it up to 197 seconds, adding Skype to the mix increases the time to 248 seconds. (150/197/248)


Then I upgraded the RAM to 1.5 GB and the times improved markedly. (91/110/102)


Then I upgraded the RAM to 2.0 GB and the times really got fast. (39/54/61).


XCode Linking Speed versus MacBook RAM

I noticed that as the times got quicker, the fraction of the CPU taken up by the linker (ld) went up. At 1GB of RAM, ld was using at most 14% of the CPU, at 2GB, it was up to 50%. It wasn't spending all it's time paging out. In fact, Activity Monitor
showed only 7 page outs after my testing versus hundreds of thousands of page outs after the 1GB testing.


You might have noticed, I didn't mention the size of my application. That is because, the size of my application is irrelevant to you. The point is, I was having slow linking, and upgrading my memory capacity improved my linking speed by around 4x for an investment of $165 (shipped) in name brand RAM. If you are having a slow linking problem, maybe you will get similar results; but you will have to measure to find out.


My brother Joe also has a RAM hungry program he relies upon, Parallels Desktop, and he tells me that bumping his MacBook to 2GB made it the fastest Windows XP computer he's ever used. (And that's with one core tied behind its back.)
 
Google+