Quick tips for fast applications

Just a short blog today

We sometimes get requests to look at performance issues. These are 10 points to consider.

1. If you probably never need something, don’t always get it ready. A typical example of this would be not to load a rarely used resource (such as a specific DLL) until you are about to use it for the first time. You get a faster startup and a smaller memory image. True, there is a delay when you first use the functionality but this will normally be in response to user action. Given the differences in speed between humans and computers, the user probably won’t notice a small delay. They will notice a longer delay if you load up several at startup.

2. Cache intelligently. If you are constantly allocating and deallocating the same sorts of object or the same Struct in unmanaged code then you are probably best off managing a cache of these objects than giving the heap manager extra work.

3. Consider your algorithms. High level approaches are flexible. Collections are powerful. Simple and low level is generally cheap.

4. Don’t do things more often than you need to. If you have a loop, only the things that change inside the loop should be inside the loop. You know this, of course… but it crops up more often than you would imagine.

5. Keep the UI responsive. This is something that Linux does rather well. It doesn’t make things faster. It actually makes them slower because the logic is more complex and UI interrupts the thread doing the real work. However, users judge application performance by how rapidly it responds to them. It is generally good to put long running tasks on worker threads and keep the UI thread for UI.

6. Don’t poll if you can use events/delegates. Why burn extra cycles?

7. Play well with others. Try to use system resources sparingly. You are not the only application on the system. If you are careful not to waste resources other applications will run better and so will you because you are not competing as much for resources.

8. Break rule 7 when you are the only application on the system. SQL server is a classic example of this. It grabs everything up front because it wants to be the only thing running on the box. SQL server is very performant.

9. Avoid network roundtrips.

10. Keep things that you will access at around the same time in the same bit of memory. Memory is accessed in pages. You are going to get a 4K read whether you ask for 4K or 2 bytes. You might as well get value for money from the read.

Signing off

Mark