18.2. Tuning the "Application" Layer

The application processing is essentially a key area where performance gains can be harvested. As you saw in the modeling exercises in Chapter 15, removing unnecessary database calls and combining functionality reduces the number of hits on the database. You can also employ the following techniques to improve the application's performance:

  • Avoid unnecessary method calls.

  • Implement object recycling and pooling.

  • Cache application data.

  • Use bulk operations.

  • Optimize method processing.

18.2.1. Avoiding Unnecessary Method Calls

As developers, we're well used to pushing functionality and decision-making lower down in the application components. However, in some situations, a large amount of processing is performed higher up for no reason. This has a detrimental effect on the application's performance. A classic example of this is during logging and tracing. The argument goes something like this: "The application components shouldn't care if logging or tracing is switched on. All they need to do is call the right method and it will decide whether to output the information." The following pseudo code demonstrates this:

Trace( LogType.Information, String.Format( "{0}:{1}:{2} Authenticating {3}, {4}",
     className, methodName, DateTime.Now, username, password) )

Trace( EnumLogType logType, string logEntry )
{
    if( IsLoggingOn )
    {
        // output trace information
    }
}

Although this type of pattern has been used widely throughout the industry, it has performance implications. ...

Get Design – Build – Run: Applied Practices and Principles for Production-Ready Software Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.