The world needs lean code!

Efficient code is green code, code that will work better on old or “light” computers used in developing countries, better on the shiny new netbooks (such as the EEE) that are coming out these days – and that will make a fast computer even faster. Efficient code, it seems, has no downside.

Jim Gettys  of OLPC says in a July 2006 interview:

There seems to be a common fallacy among programmers that using memory is good: on current hardware it is often much faster to recompute values than to have to reference memory to get a precomputed value. A full cache miss can be hundreds of cycles, and hundreds of times the power consumption of an instruction that hits in the first level cache. Making things smaller almost always makes them faster (and lower power). Similarly, it can be much faster to redraw an area of the screen than to copy a saved image from RAM to a screen buffer. Many programmer’s presumptions are now completely incorrect and we need to reeducate ourselves…

A large part of this task is raising people’s consciousness that we’ve become very sloppy on memory usage, and often there is low hanging fruit making things use less memory (and execute faster and use less power as a result). Sometimes it is poor design of memory usage, and sometimes it is out and out bugs leaking memory. On our class of a system, leaks are of really serious concern: we don’t want to be paging to our limited size flash.

In fact, much of the performance unpredictability of today’s free desktop can be attributed to the fact that several of our major applications are wasting/leaking memory and driving even systems with half a gigabyte of memory or more to paging quite quickly…

X [the X window manager] does what its told: many applications seem to think that storing pixmaps in the X server (and often forgetting about them entirely) is a good strategy, whereas retransmitting or repainting the pixmap may be both faster and use less memory. Once in a while there is a memory leak in X (generally in the graphics drivers): but almost always the problem are leaks in applications, which often forget the pixmaps they were using.RAM in the X server is just as much RAM of your program, though it is in a different address space. People forget that the X Window System was developed on systems with 2 meg of RAM, and works today on 16 megabyte iPAQ handhelds.

We need better tools; some are beginning to appear. OLPC is sponsoring a Google Summer of Code student, Eduardo Silva, from Chile, who is working on a new tool called Memphis to help with this problem.

Work done on memory consumption will benefit everyone: not everyone in the world has a 2ghz laptop with a gig or two of RAM…

Nuff said.

Confession: I’m not a coder. I help with the development of Linux only by documenting the parts I know, and by reporting bugs. While I join Jim Getty in calling for more efficient code, even much of the bloated code still represents an enormous amount of good work – it just needs some cleaning up to become awesome code.