Home Page Icon
Home Page
Table of Contents for
Java Performance Tuning
Close
Java Performance Tuning
by Jack Shirazi
Java Performance Tuning
Java Performance Tuning
Preface
Contents of This Book
Virtual Machine (VM) Versions
Conventions Used in This Book
Comments and Questions
Acknowledgments
1. Introduction
Why Is It Slow?
The Tuning Game
System Limitations and What to Tune
A Tuning Strategy
Perceived Performance
Threading to Appear Quicker
Streaming to Appear Quicker
Caching to Appear Quicker
Starting to Tune
User Agreements
Setting Benchmarks
The Benchmark Harness
Taking Measurements
What to Measure
Don’t Tune What You Don’t Need to Tune
Performance Checklist
2. Profiling Tools
Measurements and Timings
Garbage Collection
Method Calls
Profiling Methodology
Java 2 “cpu=samples” Profile Output
HotSpot and 1.3 “-Xprof” Profile Output
JDK 1.1.x “-prof” and Java 2 “cpu=old” Profile Output
Object-Creation Profiling
Monitoring Gross Memory Usage
Client/Server Communications
Replacing Sockets
Performance Checklist
3. Underlying JDK Improvements
Garbage Collection
Replacing JDK Classes
Faster VMs
VM Speed Variations
VMs with JIT Compilers
VM Startup Time
Other VM Optimizations
Better Optimizing Compilers
What Optimizing Compilers Cannot Do
What Optimizing Compilers Can Do
Remove unused methods and classes
Increase statically bound calls
Cut dead code and unnecessary instructions, including checks for null
Use computationally cheaper alternatives (strength reduction)
Replace runtime computations with compiled results
Remove unused fields
Remove unnecessary parts of compiled files
Reduce necessary parts of compiled files
Alter access control to speed up invocations
Inline calls
Remove dynamic type checks
Unroll loops
Code motion
Eliminate common subexpressions
Eliminate unnecessary assignments
Rename classes, fields, and methods
Reorder or change bytecodes
Generate information to help a VM
Managing Compilers
Sun’s Compiler and Runtime Optimizations
Optimizations You Get for Free
Literal constants are folded
String concatenation is sometimes folded
Constant fields are inlined
Dead code branches are eliminated
Optimizations Performed When Using the -O Option
Performance Effects From Runtime Options
Compile to Native Machine Code
Native Method Calls
Uncompressed ZIP/JAR Files
Performance Checklist
4. Object Creation
Object-Creation Statistics
Object Reuse
Pool Management
ThreadLocals
Reusable Parameters
Canonicalizing Objects
String canonicalization
Changeable objects
Weak references
Enumerating constants
Avoiding Garbage Collection
Initialization
Early and Late Initialization
Preallocating Objects
Lazy Initialization
Performance Checklist
5. Strings
The Performance Effects of Strings
Compile-Time Versus Runtime Resolution of Strings
Conversions to Strings
Converting longs to Strings
Converting ints to Strings
Converting bytes, shorts, chars, and booleans to Strings
Converting floats to Strings
Converting doubles to Strings
Converting Objects to Strings
Strings Versus char Arrays
Word-Counting Example
Line Filter Example
String Comparisons and Searches
Sorting Internationalized Strings
Performance Checklist
6. Exceptions, Casts, and Variables
Exceptions
The Cost of try-catch Blocks Without an Exception
The Cost of try-catch Blocks with an Exception
Using Exceptions Without the Stack Trace Overhead
Conditional Error Checking
Casts
Variables
Method Parameters
Performance Checklist
7. Loops and Switches
Java.io.Reader Converter
Exception-Terminated Loops
Switches
Recursion
Recursion and Stacks
Performance Checklist
8. I/O, Logging, and Console Output
Replacing System.out
Logging
From Raw I/O to Smokin’ I/O
Serialization
Clustering Objects and Counting I/O Operations
Compression
Performance Checklist
9. Sorting
Avoiding Unnecessary Sorting Overhead
An Efficient Sorting Framework
Better Than O(nlogn) Sorting
Performance Checklist
10. Threading
User-Interface Thread and Other Threads
Race Conditions
Deadlocks
Synchronization Overheads
Desynchronization and Synchronized Wrappers
Avoiding Serialized Execution
Timing Multithreaded Tests
Atomic Access and Assignment
Thread Pools
Load Balancing
Free Load Balancing from TCP/IP
Load-Balancing Classes
A Load-Balancing Example
Threaded Problem-Solving Strategies
Performance Checklist
11. Appropriate Data Structures and Algorithms
Collections
Java 2 Collections
Hashtables and HashMaps
Cached Access
Caching Example I
Caching Example II
Finding the Index for Partially Matched Strings
Search Trees
Performance Checklist
12. Distributed Computing
Tools
Message Reduction
CORBA Example
RMI Example
Proprietary Communications Layer
Comparing Communication Layers
Caching
Batching I
Application Partitioning
Batching II
Low-Level Communication Optimizations
Compression
Caching
Transfer Batching
Multiplexing
Distributed Garbage Collection
Databases
Performance Checklist
13. When to Optimize
When Not to Optimize
Tuning Class Libraries and Beans
Analysis
Design and Architecture
Shared Resources
Transactions
Locking
Parallelism
Data parallelism
Scaling
Distributed Applications
Object Design
Techniques for Predicting Performance
Factor in comparative performance of operations
Consider the relative costs of different types of accesses and updates
Use simulations and benchmarks
Consider the total work done and the design overhead
Focus on shared resources
Predict the effects of parallelism
Assess the costs of data conversions
Determine whether batch processing is faster
Tuning After Deployment
More Factors That Affect Performance
User Interface Usability
Training
Server Downtime
Performance Checklist
14. Underlying Operating System and Network Improvements
Hard Disks
Disk I/O
Clustering Files
Cached Filesystems (RAM Disks, tmpfs, cachefs)
Disk Fragmentation
Disk Sweet Spots
CPU
CPU Load
Process Priorities
RAM
Network I/O
Latency
TCP/IP Stacks
Network Bottlenecks
DNS Lookups
Performance Checklist
15. Further Resources
Books
Magazines
URLs
Profilers
Optimizers
Index
Colophon
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Preface
Java Performance Tuning
Jack Shirazi
Editor
Mike Loukides
Copyright © 2000 O'Reilly Media, Inc.
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset