[Contents] [Prev] [Next] [Index]

Part II: Tactics

tac·tic (tak´ tik), n. a method or maneuver to achieve a goal.

Random House Webster's Dictionary

This part provides several tactics you can use to improve the performance of your software once you've figured out where the hot spots are.

The tactics described in this section are the result of empirical testing and the Java Software performance team's years of cumulative tuning experience. While they represent what we believe to be best programming practices, none of these tactics should be applied blindly. You should always measure your software's performance and analyze the results before and after performing any optimizations.

Most of the examples in this section include small benchmarks that illustrate the trade-offs associated with different solutions. Micro-benchmarks like these help you quickly evaluate the performance characteristics of a possible solution. Keep in mind, however, that micro-benchmarks won't reveal macro-level behaviors that might be equally important. You should create and run your own benchmarks to test the results of your optimizations.

Note: This section often cites benchmark results measured in milliseconds. These results are only representative of the configuration on which they were run. Factors such as the CPU, hard disk, operating system, and JVM can all impact performance-the same benchmarks run under different configurations might show substantially different results.

There are a nearly infinite number of optimizations that could be discussed in a performance book like this one. We've chosen to focus on tactics that we've seen used successfully in real-world projects. The tactics described here reflect lessons learned from tuning code in the libraries shipped with the JRE and from helping commercial software developers tune their applications. Our goal was to provide a field manual of battle-tested tactics, rather than an encyclopedic reference of possible techniques.

Clearly, many other useful techniques exist that are not covered here. Over time, we plan to make descriptions of additional tactics available online at http://java.sun.com/docs/books/performance.

Chapter 4, I/O Performance (page 41)

Programs of all types frequently need to input and output data, and I/O bottlenecks are a common performance issue. This chapter discusses how to take full advantage of the java.io package and avoid common coding errors that can lead to poor performance.

Chapter 5, RAM Footprint (page 53)

If it's too large, the amount of memory that a program uses can adversely affect performance. This chapter shows you how to measure the amount of memory a program uses and discusses the factors that affect memory consumption.

Chapter 6, Controlling Class Loading (page 67)

Loading a large number of classes can greatly increase a program's RAM footprint and slow its start-up time. This chapter presents three different techniques for reducing RAM footprint by reducing the number of classes that are loaded.

Chapter 7, Object Mutability: Strings and Other Things (page 85)

The choices you make when handling objects need to take into account their mutability-whether or not they can be changed. This chapter discusses different ways to avoid creating a large number of intermediate objects when using both mutable and immutable objects. Minimizing the number of intermediate objects can greatly improve a program's efficiency by eliminating the allocation, initialization, and collection of those objects.

Chapter 8, Algorithms and Data Structures (page 103)

Selecting the algorithm or data structure best-suited to a particular task is one of the keys to writing high-performance software. This chapter discusses how to select and evaluate algorithms and data structures for a particular task. It also addresses how some of the conventional wisdom about algorithms applies to the Java language and highlights some of the capabilities of the data structures and algorithms built into the Java 2 platform.

Chapter 9, Using Native Code (page 129)

Java developers have often resorted to native C code to try to achieve peak performance. This chapter discusses the actual performance costs and benefits associated with native code and when using native code is a reasonable option.

Chapter 10, Swing Models and Renderers (page 145)

To create highly interactive user interfaces for Java programs, you use the JFC Swing toolkit. This chapter looks at the Swing architecture and shows how you can get the best possible performance when using Swing's models and renderers.

Chapter 11, Writing Responsive User Interfaces with Swing (page 161)

Unresponsive user interfaces are among the most obvious types of performance problems. This chapter provides a set of guidelines and tactics for designing GUIs that provide fast, sensible responses to users' input.

Chapter 12, Deployment (page 183)

How you deploy your program generally has little or no effect on your code, but it can have a large impact on the user-perceived performance of your product. This chapter discusses different deployment strategies and presents several techniques for reducing the download time of network-based applications and applets.



[Contents] [Prev] [Next] [Index]

Copyright © 2001, Sun Microsystems,Inc.. All rights reserved.