25 October 2011

Boosting performance

By Andrew Clifford

To make systems perform well, you have to focus on system design more than on high-performance coding.

One of my biggest failings professionally is that I do not think about performance when I design systems.

My attitude to performance goes back to when I was a trainee. I worked in a department where we wrote a lot of assembler. I was not keen on assembler because it was such hard work, and much preferred to work in COBOL.

The argument in favour of assembler was that assembler ran faster than COBOL. That may or may not be true, but the effort of writing in assembler meant that you easily missed the bigger picture. High-level languages free you to think more broadly about the design, which makes more difference than saving a few CPU cycles here and there.

Rather than thinking specifically about performance, adopt a design style that makes it easy to improve performance.

You need effective modularisation within a system, with simple and clear boundaries of responsibility between the different parts. This means that if one part performs badly it can be reworked and made more efficient without disrupting the rest of the system.

Use the database effectively, which means letting it do the job it was designed to do. I have seen performance problems caused by programmers trying to "better" the database by storing data in memory. This is hard to do well, and more often than not ends up slowing the system down. It is better to let the database handle all the data. With the help of a database administrator, with indexes and the correct caching, the database will easily out-perform hand-written optimisation.

The same is true of other system software. For example, in our Metrici Advisor software, I have not thought about the efficiency of sending web page to browsers, other than the general rule of keeping pages small. But because I have not designed anything exotic, we can use the standard features of the web server to optimise the pages, for example by compressing them.

At a coding level, even with large amounts of memory and fast processors, it is still important to avoid exponential processing times, which you can get from manipulating large data structures and strings in memory. Rather then doing anything clever, get to know the standard features of the programming language. Modern programming languages like Java provide standard classes for efficiently managing in-memory data; learn to use them.

Over the years I have learned that the best approach to performance is to focus on modular, flexible designs, and using the database, system software and programming languages in a standard way.

This does not guarantee that your system will perform well. In fact, it will almost certainly mean that you system will perform badly to start with.

However, it will give you a system that can be made to perform. You can tune the database and other system software. You can find and fix processing bottlenecks without disrupting the rest of the system. A modular, flexible and standard design will give you ample opportunity to improve performance, and is likely to give better results than a rigid design that focuses only on performance.