Avoid the Top 2 Performance Pitfalls: Logging and API Design
This article highlights the two most critical performance mistakes identified by Martin Thompson—excessive logging and poorly designed APIs—illustrating how logging threads can linearly increase latency and proposing better API signatures such as returning iterators or using caller‑provided collections to boost efficiency.
At the 2016 QCon conference, Martin Thompson, founder and CTO of LMAX, presented "Top 10 Performance Mistakes" and this summary focuses on the first two items.
1. Logging
Thompson argues that logging is the most common performance bottleneck. He shows a chart (see image) where the number of logging threads grows linearly with total execution time.
Testing across many logging frameworks produced the same pattern, indicating that loggers are a major performance bottleneck. Thompson recommends using asynchronous loggers and deduplicating log messages: record a message only the first time it occurs, then use a timer for subsequent repetitions.
2. API Design
Many API signatures are poorly designed from a performance perspective. Consider the following method: public String[] split(String regex) The fixed‑size array return forces the implementation to allocate a temporary structure and copy data, and callers must copy the array again if they need to sort or further process the results.
A better design is to return an Iterable instead of a fixed array: public Iterable<String> split(String regex) For even higher performance, the method can be changed to accept a destination collection supplied by the caller, eliminating the need for intermediate copies:
public void split(String regex, Collection<String> dst)This allows callers to choose the most appropriate collection type—e.g., a Set to remove duplicates or a TreeMap for ordered results—thereby improving both memory usage and execution speed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
