A performance problem can look obvious from the code while its real cost remains hidden. Measurement replaces assumptions with defined observations: exercise a representative workload, record relevant metrics, and use the results to decide where to investigate. section 7.3 section 7.3.1
A load test can identify a slow endpoint without revealing which internal operation is responsible. Instrument selected stages separately, rerun the workload, and compare invocation counts, averages, and percentiles. Choose granularity carefully: measuring every path can affect performance, and unnecessary metrics can obscure the signal. section 7.3 section 7.5
Finding the slow stage
For a word-existence endpoint, separate timers measure scanner creation and the subsequent word scan. In one run, both recorded 1,200 invocations; the 99th percentile was about 0.00073 seconds for loadFile and 0.0786 seconds for scan. That comparison directs investigation toward scanning rather than treating the endpoint as an indivisible operation. section 7.3
Listing 7.11 Measuring the word-exists logic
@Override
public boolean wordExists(String word) {
Timer loadFile = metricRegistry.timer("loadFile");
try (Scanner scanner = loadFile.time(() -> new
Scanner(filePath.toFile()))) { #A
Timer scan = metricRegistry.timer("scan");
return scan.time( #B
() -> {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (word.equals(line)) {
return true;
}
return false;
});
} catch (Exception e) {
throw new RuntimeException("Problem in wordExists for word: " + word, e);
}
}The listing shows where the two timers surround scanner creation and the scan loop. section 7.3
AI can help add instrumentation, but static guesses and generated metrics still need runtime verification. Supply the expected traffic, run the benchmark, inspect the numbers, and give those results back before requesting optimization. Keep changes focused on the measured hot path; broad rewrites add review, deployment, and monitoring costs. section 7.3.1 section 7.5
Measure outcomes as well as activity. Review capacity released by automation is not itself delivered value: record it as capacity, then measure what it produces. Likewise, perceived developer speed is a poor substitute for wall-clock time and error count. section 10.5.3 section 1.1





