Table of Contents
Preface. Introduction. I: STRATEGIES.
1. What Is Performance?
Computational Performance.
RAM Footprint.
Startup Time.
Scalability.
Perceived Performance.
2. The Performance Process.
Developing a Performance Process.
References on Object-Oriented Design.
3. Measurement Is Everything.
Benchmarking.
Profiling.
Dealing with Flat Profiles.
II: TACTICS.
4. I/O Performance.
Basic I/O.
Serialization.
5. RAM Footprint.
Computing RAM Footprint.
What Contributes to Footprint?
Class Loading.
6. Controlling Class Loading.
Eager Class Loading.
Reducing the Number of Classes.
Running Multiple Programs.
7. Object Mutability: Strings and Other Things.
Lots of Little Objects.
Handling String Objects.
Mutable Objects in AWT and Swing.
Other Mutable Object Tactics.
Mutable Object Case Study.
Small Objects and the Modern JVM.
Array Mutability.
8. Algorithms and Data Structures.
Selecting Algorithms.
Using Recursive Algorithms.
Beyond Simple Algorithms.
Selecting Data Structures.
Collections Example.
References on Algorithms and Data Structures.
9. Using Native Code.
Native Graphics Example.
Examining JNI Costs.
Native Code Case Studies.
10. Swing Models and Renderers.
Swing's Component Architecture.
Scalable Components.
11. Writing Responsive User Interfaces with Swing.
Guidelines for Responsive GUIs.
Using Threads in Swing Programs.
Using Timers in Swing Applications.
Responsive Applications Use Threads.
Example: Searching the Web.
12. Deployment.
Compiler Options.
JAR Files.
Packaging Utilities.
Dynamic Downloading.
Appendices.
A. The Truth About Garbage Collection.
Why Should You Care About Garbage Collection?
The Guarantees of GC.
The Object Lifecycle.
Reference Objects.
References on Garbage Collection.
B. The Java HotSpot Virtual Machine.
HotSpot Architecture.
Runtime Features.
HotSpot Server Compiler.
X Flags.
XX Flags.
References.
Index 221. 0201709694T04062001.
Forewords & Introductions
PREFACE:
Author's Note
In 1997, I was hired as a contractor to work on the Java(TM) Foundation Classes (JFC) Swing toolkit (Swing). This was an ambitious endeavorSwing was slated to become the new standard for developing Graphical User Interfaces (GUIs) with the Java programming language. Prior to the release of Swing, the only GUI toolkit available with the Java platform was the Abstract Window Toolkit (AWT), a fairly primitive GUI toolkit by 1990s standards. While AWT was hobbled by a "lowest common denominator" design, Swing was designed to be a state-of-the-art toolkit. Written entirely in the Java programming language, it offered a powerful Model-View architecture, an advanced widget set, and a revolutionary pluggable look-and-feel (PLAF) system. When JFC was released in mid-1998, it was quickly adopted by thousands of eager developers.
As with any successful new product, along with stories of success came some bitter complaints. Some developers complained about architectural and philosophical issues. Others complained about bugs or the lack of a particular feature. However, the complaints I personally found most troubling were that programs written with Swing were slow.
I convinced my manager to let me spend a week looking into Swing's performance issues, downloaded a trial copy of a profiling package, and started poking at different parts of the toolkit.
It turned out that there were several areas where performance improvements could be made relatively easily. At the end of the week, I wrote a report on my findings and sent it to the rest of the Swing engineering team. Other members of the team got caught up inthespirit of performance tuning and began doing their own analyses. Over the next few months, I spent more and more of my time working on analysis and tuning and the Swing team made numerous performance enhancements. Many of the techniques described in this book are based on the knowledge gained while we were tuning Swing.
In late 1998, we shipped a new version of Swing that was more than twice as fast for typical tasks than the previous release. However, while many developers were pleased with the improvements, we were troubled to see that we still received numerous complaints about performance. Clearly the problem was more complex than we first thought.
I joined the performance team in Sun's Java Software unit in late 1998 and worrying about performance issues became my full-time job. In an effort to better understand the performance issues we and our developers face, I spend a lot of time talking with developers who are working on serious, real-world Java technology-based systems. Developers sometimes point out areas where changes in the libraries or VM could improve the performance of their programs. Part of my group's charter is to help make sure those changes, when appropriate, make their way into the runtime environment.
When working with developers, we also often find areas where changes to their program code can improve performance. We've found that there are a number of common mistakes and misconceptions about the performance characteristics of Java technologies and even about performance tuning in general.
The goal of this book is to share what we've learned about performance tuning Java technology-based systems with a wide audience. We hope that it will prove to be a valuable reference for you.
Steve Wilson
Sun Microsystems
About This Book
The information in this book will help you write high-performance software for the Java platform. It presents both high-level strategies for incorporating performance tuning into your software development process and code-level performance tuning tactics.
The two parts of the book approach performance tuning from different perspectives, providing a holistic view of the performance tuning process.
- Part I: Strategies provides a high-level overview of the performance tuning process. It focuses on general strategies that you can incorporate into the development process to improve the performance of Java technology-based systems.
- Part II: Tactics focuses on specific techniques for improving performance once you've figured out where the hot spots and bottlenecks are.
The higher-level information in the Strategies part is intended for a broad audience, including software engineers, engineering managers, technical leads, and quality assurance specialists involved in the development of Java technology-based solutions. The information in the Tactics part is geared toward intermediate to advanced developers familiar with the Java programming language who are looking for concrete coding techniques they can use to speed up their software.
The Strategies chapters are best read as a single piece, but the Tactics part does not need to be read linearlyyou can go directly to whatever topic interests you most.
The two appendices at the end of the book provide information about garbage collection and the HotSpot(TM) virtual machine (VM) and how they can impact performance.
Performance Measurements
Unless otherwise noted, all performance measurements described in this book were run on a pre-release build of the Java 2 Standard Edition (J2SE) v. 1.3 using the HotSpot Client VM on the Microsoft Windows operating system.
Specific performance results are only representative of the configuration on which they are run. Factors such as the CPU, hard disk, operating system, and Java runtime environment (JRE) can all impact performancekeep in mind that the same benchmarks run under different configurations might yield substantially different results.
Code Samples
Complete code for the snippets, sample programs, utilities, and benchmarks used in this book is available online at ...
Read an Excerpt
PREFACE:
Author's Note
In 1997, I was hired as a contractor to work on the Java(TM) Foundation Classes (JFC) Swing toolkit (Swing). This was an ambitious endeavorSwing was slated to become the new standard for developing Graphical User Interfaces (GUIs) with the Java programming language. Prior to the release of Swing, the only GUI toolkit available with the Java platform was the Abstract Window Toolkit (AWT), a fairly primitive GUI toolkit by 1990s standards. While AWT was hobbled by a "lowest common denominator" design, Swing was designed to be a state-of-the-art toolkit. Written entirely in the Java programming language, it offered a powerful Model-View architecture, an advanced widget set, and a revolutionary pluggable look-and-feel (PLAF) system. When JFC was released in mid-1998, it was quickly adopted by thousands of eager developers.
As with any successful new product, along with stories of success came some bitter complaints. Some developers complained about architectural and philosophical issues. Others complained about bugs or the lack of a particular feature. However, the complaints I personally found most troubling were that programs written with Swing were slow.
I convinced my manager to let me spend a week looking into Swing's performance issues, downloaded a trial copy of a profiling package, and started poking at different parts of the toolkit.
It turned out that there were several areas where performance improvements could be made relatively easily. At the end of the week, I wrote a report on my findings and sent it to the rest of the Swing engineering team. Other members of the team got caught up in thespirit of performance tuning and began doing their own analyses. Over the next few months, I spent more and more of my time working on analysis and tuning and the Swing team made numerous performance enhancements. Many of the techniques described in this book are based on the knowledge gained while we were tuning Swing.
In late 1998, we shipped a new version of Swing that was more than twice as fast for typical tasks than the previous release. However, while many developers were pleased with the improvements, we were troubled to see that we still received numerous complaints about performance. Clearly the problem was more complex than we first thought.
I joined the performance team in Sun's Java Software unit in late 1998 and worrying about performance issues became my full-time job. In an effort to better understand the performance issues we and our developers face, I spend a lot of time talking with developers who are working on serious, real-world Java technology-based systems. Developers sometimes point out areas where changes in the libraries or VM could improve the performance of their programs. Part of my group's charter is to help make sure those changes, when appropriate, make their way into the runtime environment.
When working with developers, we also often find areas where changes to their program code can improve performance. We've found that there are a number of common mistakes and misconceptions about the performance characteristics of Java technologies and even about performance tuning in general.
The goal of this book is to share what we've learned about performance tuning Java technology-based systems with a wide audience. We hope that it will prove to be a valuable reference for you.
Steve Wilson
Sun Microsystems
About This Book
The information in this book will help you write high-performance software for the Java platform. It presents both high-level strategies for incorporating performance tuning into your software development process and code-level performance tuning tactics.
The two parts of the book approach performance tuning from different perspectives, providing a holistic view of the performance tuning process.
- Part I: Strategies provides a high-level overview of the performance tuning process. It focuses on general strategies that you can incorporate into the development process to improve the performance of Java technology-based systems.
- Part II: Tactics focuses on specific techniques for improving performance once you've figured out where the hot spots and bottlenecks are.
The higher-level information in the Strategies part is intended for a broad audience, including software engineers, engineering managers, technical leads, and quality assurance specialists involved in the development of Java technology-based solutions. The information in the Tactics part is geared toward intermediate to advanced developers familiar with the Java programming language who are looking for concrete coding techniques they can use to speed up their software.
The Strategies chapters are best read as a single piece, but the Tactics part does not need to be read linearlyyou can go directly to whatever topic interests you most.
The two appendices at the end of the book provide information about garbage collection and the HotSpot(TM) virtual machine (VM) and how they can impact performance.
Performance Measurements
Unless otherwise noted, all performance measurements described in this book were run on a pre-release build of the Java 2 Standard Edition (J2SE) v. 1.3 using the HotSpot Client VM on the Microsoft Windows operating system.
Specific performance results are only representative of the configuration on which they are run. Factors such as the CPU, hard disk, operating system, and Java runtime environment (JRE) can all impact performancekeep in mind that the same benchmarks run under different configurations might yield substantially different results.
Code Samples
Complete code for the snippets, sample programs, utilities, and benchmarks used in this book is available online at ...