Performance Checklist
Most of these suggestions apply only after a bottleneck has been identified:
Ensure that performance tests are run with the same amount of I/O as the expected finished application. Specifically, turn off any extra logging, tracing, and debugging I/O.
Use
Runtime.traceMethodCalls()
, when supported, to count I/O calls.Redefine the I/O classes to count I/O calls if necessary.
Include logging statements next to all basic I/O calls in the application.
Parallelize I/O by splitting data into multiple files.
Execute I/O in a background thread.
Avoid the filesystem file-growing overhead by preallocating files.
Try to minimize the number of I/O calls.
Buffer to reduce the number of I/O operations by increasing the amount of data transfer each I/O operation executes.
Cache to replace repeated I/O operations with much faster memory or local disk access.
Avoid or reduce I/O calls in loops.
Replace
System.out
andSystem.err
with customizedPrintStream
classes to control console output.Use logger objects for tight control in specifying logging destinations.
Try to eliminate duplicate and unproductive I/O statements.
Keep files open and navigate around them rather than repeatedly opening and closing the files.
Consider optimizing the Java
byte
-to-char
(andchar
-to-byte
) conversion.Handle serializing explicitly, rather than using default serialization mechanisms.
Use transient fields to avoid serialization.
Use the
java.io.Externalizable
interface if overriding the default serialization ...
Get Java Performance Tuning 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.