A performance optimization can make a system harder to maintain or operate without improving the workflow that matters. Complexity may live in code, maintenance, or the components a system relies on. When traffic and latency requirements are unclear, favor maintainable code until measurements justify a more complicated design. section 7.1
A one-word change with hidden costs
Replacing a Java account lookup’s stream() with parallelStream() adds multithreading: processing should be stateless, the thread pool needs monitoring, and debugging becomes harder. Splitting work also costs time. For an assumed workload of up to 10,000 accounts, a JMH benchmark found nearly identical performance, so the result did not justify the operational complexity. section 7.1.1
Listing 7.5 Viewing the performance benchmark output
CH05.premature.AccountsFinderPerformanceBenchmark.baseline avgt 10 0.027 ± 0.002 ms/op CH05.premature.AccountsFinderPerformanceBenchmark.parallel avgt 10 0.030 ± 0.002 ms/op
Compare the measured baseline and parallel lookup times; the small code change does not expose the operational costs. section 7.1.1
AI-generated optimizations can magnify the same mistake. A prompt directing an LLM away from single-threaded processing produced several concurrent strategies without establishing the expected dataset size. Its custom benchmark also assumed 100,000 accounts and had potential measurement problems. Give the model realistic workload constraints, and verify its proposals with a reliable benchmark rather than trusting the generated test. section 7.1.2 section 7.5
Before accepting added complexity:
- State the expected input size, traffic, and performance goal; compare alternatives under those assumptions. section 7.1 section 7.1.1
- Measure the hot path. A slower but rarely called endpoint may consume less total processing time than a faster, frequently called one. section 7.2
- Account for review, deployment, monitoring, and cognitive load. Broad changes and excessive metrics can make optimization harder to evaluate. section 7.5














