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.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Avoid the Top 2 Performance Pitfalls: Logging and API Design

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.

Logging performance chart
Logging performance chart

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendJavaperformanceloggingapi-design
Java High-Performance Architecture
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.