Is it normal to wait for your computer? Why should I wait 5 seconds when I click on a menu? Why does it sometimes take half a minute to open a new document? Developers, optimize your code, if only as a matter of public service! What about making it a New Year resolution?

Why is my Mac laptop slower than my iPad?

Apple cares about iPad performance

Apple cares about iPad performance

I have a serious issue with the fact that on a laptop with 8G of RAM, 1TB of hard disk, a quad-core 2GHz i7, I spend my time waiting. All the time. For long, horribly annoying pauses.

Just typing these few paragraphs had Safari go into “pause” twice. I type something and it takes ten seconds or so with nothing showing up on screen, and then it catches up. Whaaaaat? How did programmers manage to write code so horribly that a computer with a quad-core 2.6GHz i7 can’t even keep up with my typing? Seriously? The Apple II, with its glorious 1MHz 8-bit 6502 never had trouble keeping up, no matter how fast I typed. Nor did Snow Leopard, for that matter…

Even today, why is it that I always find myself waiting for my Mac as soon as I have 5 to 10 applications open, when a poor iPad always feel responsive even with 20 or 30 applications open at the same time? Aren’t we talking about the same company (Apple)? About the same core operating system (Darwin being the core of both iOS and OSX)? So what’s the difference?

The difference, folks, is optimizations. Code for iOS is tuned, tight, fit. Applications are programmed with severe hardware limitations in mind. The iPad, for instance, is very good at “pausing” applications that you are not using and recalling them quickly when you switch to them. Also, most applications are very careful in their use of resources, in particular memory and storage. Apple definitely cares about the performance of the iPad. There was a time the performance of the Mac mattered as well, but that was a long time ago.

Boiled frog syndrome : we slowly got used to desktops or laptops being slower than tablets, but it’s just plain stupid.

Lion and Mountain Lion are Dog Slow

It's obvious why they called it Lion...

It’s obvious why they called it Lion…

I’ve been running every single version of MacOSX since the Rhapsody days. Up until Snow Leopard, each release was a definite improvement over the previous version. Lion and Mountain Lion, on the other hand, were a severe step backwards…

Lion and Mountain Lion were not just loaded with features I didn’t care about (like crippling my address book with Facebook email addresses), they didn’t just break features I relied on on a daily basis (like full screen applications that works with multiple monitors, or RSS feeds). They were slow.

We are not talking about small-scale slowness here. We are talking about molasses-fed slugs caught in a tar pit, of lag raised to an art form, of junk code piling up at an industrial scale, of inefficiency that makes soviet car design look good in comparison.

And it’s not just me. My wife and my kids keep complaining that “the machine lags”. And it’s been the case with every single machine I “upgraded” to Lion or Mountain Lion. To the point where I’m not upgrading my other machines anymore.

In my experience, the core issue is memory management. OSX Lion and Mountain Lion are much worse than their predecessors at handling multiple programs. On OSX, the primary rule of optimization seems to be “grab 1GB of memory first, ask questions later.” That makes sense if you are alone: RAM is faster than disk, by orders of magnitude, so copying stuff there is a good idea if you use it frequently.

But if you share the RAM with other apps, you may push those other apps away from memory, a process called “paging“. Paging depends very largely on heuristics, and has major impact on performance. Because, you see, RAM is faster than disk, by orders of magnitude. And now, this plays against you.

Here is an example of a heuristic that I believe was introduced in Lion: the OS apparently puts aside programs that you have not been using for a long while. A bit like an iPad, I guess. On the surface, this seems like a good idea. If you are not using them, free some memory for other programs. But this means that if I go away from my laptop and the screen saver kicks in, it will eat all available RAM and push other programs out. When I log back in… I have 3GB of free RAM and a spinning beach ball. Every time. And even if the screensaver does not run, other things like backupd (the backup daemon) or Spotlight surely will use a few gigabytes for, you know, copying files, indexing them, stuff.

Boiled frog syndrome : we slowly got used to programs using thousands of Mac128K worth of memory to do simple things like running a screensaver. It’s preposterous.

Tuning memory management is very hard

Virtual Memory is complicated

Virtual Memory is complicated

The VM subsystem, responsible for memory management, was never particularly good in OSX. I remember a meeting with an Apple executive back in the times OSX was called Rhapsody. Apple engineers were all excited about the new memory management, which was admittedly an improvement over MacOS9.

I told the Apple person I met that I could crash his Mac with 2 minutes at the keyboard, doing only things a normal user could do (i.e. no Terminal…) He laughed at me, gave me his keyboard and refused to even save documents. Foolish, that.

I went to the ancestor of Preview.app, opened a document, clicked on “Zoom” repeatedly until the zoom factor was about 6400% or so. See, in these times, the application was apparently allocating a buffer for rendering that was growing as you zoomed. The machine crawled to a halt, as it started paging these gigabytes in and out just to draw the preview on the screen. “It’s dead, Jim“, time to reboot with a long, hard and somewhat angry press on the Power button.

That particular problem was fixed, but not the underlying issue, which is a philosophical decision to take control away from users in the name of “simplicity“. OS9 allowed me to say that an App was supposed to use 8M of RAM. OSX does not. I wish I could say: “Screen Saver can use 256M of RAM. If it wants more, have it page to disk, not the other apps.” If there is a way to do that, I have not found it.

Boiled frog syndrome : we have slowly been accustomed by software vendors to give away control. But lack of control is not a feature.

Faster machines are not faster

A 1986 Mac beats a 2007 PC

A 1986 Mac beats a 2007 PC

One issue with poor optimizations is that faster machines, with much faster CPUs, GPUs and hard disks, are not actually faster to perform the tasks the user expects from them, because they are burdened with much higher loads. It’s as if developers always stopped at the limit of what the machine can do.

It actually makes business sense, because you get the most of your machine. But it also means its easy to push the machine right over the edge. And more to the point, an original 1986 Mac Plus will execute programs designed for it faster than a 2007 machine. I bet this would still hold in 2013.

So if you have been brainwashed by “Premature optimization is the root of all evil“, you should forget that. Optimizing is good. Optimize where it matters. Always. Or, as a colleague of mine once put it, “belated pessimization is the leaf of no good.”

Boiled frog syndrome : we have slowly been accustomed to our machines running inefficient code. But inefficiency is not law of nature. Actually, in the natural world, inefficiency gets you killed. So…


Stereoscopy: What works, what doesn’t

In the past months, we have been looking for a relatively cheap way to present the output of a 3D application using stereoscopy. Our objective was to see how an application could generate stereoscopic output using commercially-available low-cost hardware. Our expectation was that a budget 3D laptop and a budget 3D projector would make for a budget 3D presentation solution.

The solution that ended up working was a total surprise to us, so I thought I’d share…

Budget 3D laptop and projector

We recently purchased two pieces of equipment with a “3D” sticker on them. One was an ACER Aspire 5740D laptop, the other was an Optoma DW318 projector. Both can be considered entry level hardware, around $700 each with glasses.

This family of Acer laptops uses a polarized display and passive glasses. Even and odd scan-lines are polarized differently, meaning that you get half the vertical resolution when using stereoscopy. Native resolution is 1366×768. It comes equipped with an ATI Radeon 4570 and some 3D software from TriDef. It is also covered with at least 5 stickers and littered with various nagware (software based on the “we’ll bug you until you pay” school of design) and other software nuisances, almost guaranteeing a supremely annoying unpacking experience.

The Optoma is labelled as “3D-ready”. It uses active glasses based on Texas Instrument’s DLP-Link technology. Native resolution is 1280×800. The active glasses mean that you get the full resolution with 120Hz frame-sequential input, with only a barely noticeable decrease in frame rate (60Hz for each eye). It can also reportedly take 60Hz field-sequential input up to 480i, but we didn’t test that. There is practically no manual (at least as far as 3D is concerned), and the manual that came with the glasses didn’t help much either (I’m still not sure I know how to switch the glasses off).

No OpenGL stereoscopy on Windows

Our test application uses standard OpenGL quad-buffer support. We need OpenGL because we want the application to run on Macs and Linux machines as well, not just Windows. So DirectX is a no-go. However, we also evaluated how things worked with DirectX just in case we had no other choice.

With the Acer, the ATI “Catalyst” drivers simply tell us that there is no OpenGL quad buffer support. As soon as we try to use the buffers, we get an error (1282: Invalid operation). This is a disappointment, as quad-buffer support for DirectX was one of the advertised features for recent Catalyst drivers. Apparently, this only means that a third-party driver, either from iZ3D or TriDef, can silently convert non-stereoscopic games into stereoscopic games.

It makes sense from a business point of view, since all the majority of users will care about is 3D games, which mostly use DirectX nowadays. But if you want to programmatically produce stereoscopic 3D-accelerated output using OpenGL, which should theoretically be simpler, it just doesn’t work out of the box.

I spent a little bit of time trying to find drivers from iZ3D or TriDef that would support OpenGL quad-buffer on this machine. No such luck.

  • The iZ3D setup page prominently shows “OpenGL QB driver for iZ3D”. However, when I installed the driver, it didn’t work for me. Only DirectX would show up. It took me a while to see this little note somewhere:

Note! OpenGL QB is for 32-bit systems only and can not be run properly on 64-bit systems.

You guessed it: my system is 64-bit, so no OpenGL for me.

  • The experience with the TriDef setup was exactly similar. At first, it looks promising: “The DDD TriDef Visualizer Program is ideal for anyone interested in enabling their application for output to stereoscopic displays.” That is, until you click on the link to get the SDK, only to be told:

PLEASE NOTE: TriDef Visualizer OpenGL SDK has been RETIRED and is no longer available for sale.

If someone at Microsoft has been tasked with the job of killing OpenGL on Windows, it looks like they have been doing a rather good job. In any case, we were unable to find any combination of drivers on 64-bit Windows that would allow us to use 3D stereoscopy from OpenGL. If you know of any combination that works, please comment here.

Working around lackluster OpenGL support

The structure of the screen on the Acer is really simple. Every other line on the screen is polarized differently. So in order to produce a stereoscopic image, you don’t really need a driver. All you need is the good old OpenGL stencil buffer, as explained here. You then render one eye with all even lines masked out, and then another eye with all odd lines masked out.

This worked well, and we were soon able to get some basic stereoscopy working. It only took a couple of hours of coding. I only wish this coding had not been necessary on a machine that came littered with 3D stickers and pictures of 3D pirates on the box!

Then, we could start experimenting with stereoscopic rendering and judge by ourselves how the effect played out. Unfortunately, while it worked to some extent, it was not entirely satisfying…

The drawbacks of interlaced stereoscopy

The most annoying issue with this setup, as we quickly discovered, is that you lose half of the vertical resolution. It may not seem like much, but this actually makes text totally unreadable. “Who needs text in a stereoscopic display?“, you may wonder. Well, Google Earth, for one, uses a lot of text. And this is practically the only non-game application I managed to get working on the Acer with the built-in software.

The problem is that the Windows user interface itself uses a fair amount of text and small drawings. Since the glasses actually block every other line, here is what your desktop looks like when you wear the glasses:

Windows 7 desktop, as seen through passive glasses

Windows 7 desktop, as seen through passive glasses

The effect is actually much more annoying than that, because what your left eye and your right eye see is different. I just can’t stand looking at my desktop like this for long. So what happens is that you spend your time putting the glasses on, then removing them, then putting them back on. After a short while, the game stops being funny and you wish you had bought active glasses instead. This probably doesn’t impact gamers much, but in our case, it is almost a deal breaker…

No stereoscopy on Windows with a low-cost projector

In order to address this issue, our next experiment was with the Optoma DW318 projector. I got this projector from Saturn at a bargain price. The vendor was actually quite honest that they had not tried 3D and didn’t know if it worked. Also, this projector is marketed as “3D-ready”, so I wasn’t entirely sure that we’d get anywhere. But we naively hoped that if we connected a “3D-ready” projector to a laptop that has stereoscopic 3D support as its main selling point, we stood a decent change of getting a stereoscopic image on the projector.

Boy! Were we naive last week!

If the built-in stereoscopic software on the Acer laptop has any kind of support for the Optoma projector, it is rather well hidden. I tried various options, but as far as I can tell, stereoscopy on the Acer is meant to be restricted to the built-in screen. That’s rather odd! What would you think of a color laptop than can only supply black-and-white pictures to external displays?

I tried supplementing the anemic built-in software. Downloading drivers from iZ3D, I was able to get a 3D image from their test and setup application. But still, I was not able to get a stereoscopic image from Google maps on the projector, however, something that works on the built-in screen of the Acer laptop.

The overall feeling is that this stuff was rushed out of the door before it’s really ready.

The Good Surprise: on a Mac, It Just Works!

We also have Apple Macbook Pro notebooks and Linux laptops and virtual machines. During testing, Linux didn’t do much better than Windows. However, OpenGL on the Mac accepted quad-buffer (stereoscopic) mode. Compared to Windows, the primary difference was that we did not get the 0x502 = 1282 error (OpenGL invalid operation) when selecting the back-left or back-right buffers. Tweaking a bit, we had gotten what looked like a stereoscopic output on the built-in display of the Mac laptops or on external displays, with fuzzy blurry images.

Of course, without glasses, that’s all these were: fuzzy blurry images, not that useful unless you can blink really really fast.

Actually, everything was not all smooth and fuzzy at first. OpenGL was apparently doing something smart there, but we were clearly pushing it a bit. For example, if running an OpenGL application under the debugger and putting the laptop to sleep, MacOSX would die a little too often for my taste (like: almost every single time). Another interesting issue was that if you had any stereoscopic application running, switching desktops with Spaces would just kill the window server (the MacOSX blue screen of death). That was really annoying. I filed a couple of bug reports with Apple. Stereoscopy was apparently working to some extent, but it still made for a very un-Apple dangerous user experience.

That was last month, when MacOSX 10.6.4 was all the rage. Imagine my surprise when 10.6.5 came out. All the issues I had were fixed with 10.6.5. And this certainly took some work from Apple engineers. Now, when you switch spaces with a stereoscopic application (and only a stereoscopic application), something happens that you can notice visually, almost as if some part of the window server was rebooted or something. It’s just weird, but at least, it’s just solid now. Kudos, Apple for fixing something that could easily have passed for a corner case with exactly one user in the world.

Anyway, I figured that it was worth trying to hook a Macbook Pro to the projector and see what we got. And IT JUST WORKED! We got perfect, high quality stereoscopic images the first time we tried.

Or almost.

How can you make glasses complicated?

Clearly, I had two pictures on the screen. And when I wore the glasses, I had only one picture. So something was working. But the result was still disappointing. It looked boringly flat, nothing like what I expected.

I tried several settings on the projector, checked that 3D was enabled in the firmware menu. I adjusted the eye distance to try to increase the depth. The effect of increasing eye distance was clearly visible with the naked eye, as the left and right pictures became more distant from one another. But with the glasses, still no feeling of depth.

Until I tried to switch off the glasses while wearing them, using the little red button. And I noticed that the picture moved. It was still flat, but it had moved in front of me. Hmmm?!?

So I tried again to see if the picture would move again. And I almost fell on my back. The effect was intense, in no small part because I had pushed the eye distance so high. A few adjustments later, I was back to the original setting, and I had true, breathtaking stereoscopy.

Guess what: some bozo working for Optoma or whoever designed the glasses thought it was a good idea to have three settings: left eye only, right eye only and stereoscopic. I’m sure there’s a good reason for that, but as far as I can tell, the manual only talks about on and off settings.

Trying Windows on a Macintosh

Once we knew that the Macs could drive the Optoma projctor in stereoscopic mode, we thought we also had a Windows solution. See, all recent Macs can run Windows using Bootcamp. We figured that it was a simple matter of switching to Windows, installing the latest Nvidia drivers, and boom.

Well, not quite.

First, Nvidia won’t let us install drivers on a Mac. We are supposed to ask Apple. Of course, there are workarounds. So quickly, we were able to get the latest drivers to install on the Mac. These drivers that are ostensibly designed for stereoscopy. But it still doesn’t work with the Optoma projector.

See, Nvidia has their own little 3D project called 3Dvision. You’d think that since 3Dvision is about supporting stereoscopy, we stood a chance of making it work with an Optoma stereoscopic projector.

And you’d be wrong. It doesn’t work. With OpenGL, you get the same dreaded error 1282.

According to some posts on the Internet, it used to work relatively well with much older Nvidia drivers and cards. But apparently, Nvidia is now trying to leverage their position as a key provider of graphics chips to force third parties to “certify” projectors. The Optoma HD67 is certified and reportedly recognized by 3Dvision drivers. The DW318 is not certified, and therefore not recognized.

If this is a trick to try and force me to buy Nvidia glasses, it’s not just a cheap trick, it’s a stupid trick. The Nvidia solution uses a small infrared emitter. If I’m projecting on a large screen, I doubt this emitter would be good enough to cover a medium-sized room. I suspect that the technique used in DLP-Link, which uses data sent on the screen by the projector, is much better suited to sharing with a large audience.

Anyway, the very same Optoma projector just works on the very same Macbook pro when running MacOSX instead of Windows 7. So this is clearly a software block from Nvidia rather than some subtle hardware limitation. If you are the Nvidia or Microsoft bozo who is responsible for this fiasco, here is a hint: why don’t you get it fixed?

Conclusion: Don’t Trust Marketing

To summarize my experience:

  • The Acer 5740DG offers some basic stereoscopy, but support for OpenGL is underwhelming. OpenGL stereoscopy won’t work with the pre-installed 64-bit version of Windows 7. This Acer laptop is designed primarily for games, although it may be a bit underpowered for that purpose. For any windowed 3D application, or any application that shows text, dialog boxes or other small elements, the stereoscopic experience is highly frustrating because you don’t see half of the screen while wearing the glasses.
  • The Optoma DW318 is a very capable 3D projector if you can make it work in your configuration. The picture is actually much better with the glasses in stereoscopy mode, with rich deep blacks and well balanced colors. Without the glasses, the picture looks a bit washed out. Still, it’s a decent value, and a good way to demo stereoscopy to more than one person. I only wish they didn’t charge $100 or so for a pair of cheap plastic glasses with $0.0027 worth of electronics components in them.
  • Nvidia and ATI are both equally incompetent at delivering OpenGL stereoscopy on Windows 7. Part of it may be Microsoft pushing DirectX, but I believe the driver vendors are equally to blame. I couldn’t get OpenGL stereoscopy to work whether with ATI or Nvidia, whether with built-in screens or external projectors.
  • MacOSX 10.6.5 has full support for OpenGL stereoscopy, and when connected to a 3D-ready projector like the Optoma DW318, it just works the way it should. This is advertised nowhere, which makes it even sweeter.

In short, those who talk the most about 3D (Nvidia, Acer) are those who deliver the least. By contrast, Apple, who doesn’t say a word about stereoscopy, delivers flawless OpenGL stereoscopy support as far as I can tell. And Optoma, who labels its DW318 with a rather understated “3D-ready”, has made the process of projecting in 3D both inexpensive and painless.

As seen on PC…

Just saw this on my PC:

Provider could not perform the action since the context was acquired as silent (Error 0x80090022).

This inane sentence is supposed to be some sort of error message in a VPN. Hello?!? What is that supposed to mean? This kind of ill-conceived software behavior is exactly why so many people have trouble with technology in general and computers in particular.

Oh, the message really means: “Cannot connect the VPN because there is no underlying network”, as far as I can tell based on experimentation with the VPN software that emits said message…

Longhorn virtualization

Microsoft recently published a video of their upcoming Longhorn virtualization. Interestingly, they demonstrate a feature that they claim no competitor can match, namely an 8-core virtual machine. I’m really curious to see the final product. Being in the field, I know exactly what kind of problem virtual machines run into with scalability.

A key problem is relatively simple to explain, and having explained it to many HP customers, I see no reason not to talk about it on this blog. When you schedule more than one virtual CPU, there are essentially two ways of doing it.

  • You can use something called gang scheduling. In that case, all virtual CPUs run at the same time. One major benefit is that if a virtual CPU is waiting for a lock, the virtual CPU that holds the lock is also running. So there is no major increase in lock contention, a key factor in scalability. The major drawback is that if you have an 8-way virtual machine with 1 CPU busy, it actually consumes 8 CPUs. That is not very good use of the CPUs.
  • An alternative is to schedule each virtual CPU individually. This is much more difficult to get right, in particular because of the lock contention issue outlined above. On the other hand, the benefit in terms of CPU utilization for virtual machines that use only some of their virtual CPUs are enormous.

So here is a test I’m interested in running on Longhorn virtualization when it becomes available: if I have two 4-way virtual machines on an 4-way hardware, and if I start one “spinner” process in each that counts as fast as possible, do I see:

  • 4 processors pegged at 100%, with the two spinners running at half their nominal rate, since they each get essentially 50% of one CPU? As far as I know, this is the behavior for VMware, and it’s characteristic of gang scheduling.
  • 2 processors pegged at 100% and 2 processors sitting mostly idle, with each spinner getting 100% of a CPU? This is the behavior of Integrity Virtual Machines.

The bottom line is: there is a serious trade off between scalability and efficient use of resources. If Microsoft managed to solve that problem, kudos to them.