Rule 11:Consider the performance consequences of your API design decisions
Consider the performance consequences of your API design decision: Making a public type mutable may require a lot of needless defensive copying. Similarly, using inheritance in a public class where composition would have been appropriate ties the class forever to its superclass.
As a final example,
using an implementation type rather than an interface in an API ties you to a specific implementation, even though faster implementations may be written in the future
measure performance before and after each attempted optimization. Optimize using profiling tools: Another tool that deserves special mention is jmh, which is not a profiler but a microbenchmarking framework that provides unparalleled visibility into the detailed performance of Java code.
To summarize, do not strive to write fast programs—strive to write good ones;
speed will follow.