Expected traffic gives an optimization proposal a realistic workload bound. Specifying that AccountFinder handles at most 10,000 accounts changes the recommendation from parallel processing to a map-based lookup; benchmark results can then test the proposal. section 7.1.3 section 7.5
Bound the AccountFinder workload
For a search among at most 10,000 accounts, an AI proposal argues that parallel overhead outweighs its benefits and suggests a HashMap lookup. The implementation is then added as a benchmarked strategy for comparison with existing approaches. section 7.1.3
this.accountMap = new HashMap<>(accounts.size() * 4 / 3 + 1); #A
for (Account account : accounts) {
accountMap.put(account.getId(), account);
}
#B
public Optional<Account> accountHashMap(Integer id) {
return Optional.ofNullable(accountMap.get(id));
}
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Optional<Account> hashMapSampleTime() {
Integer id = searchIds.get(random.nextInt(searchIds.size()));
return accountFinder.accountHashMap(id);
}
@Benchmark
public boolean hashMapExists() {
Integer id = searchIds.get(random.nextInt(searchIds.size()));
return accountFinder.accountHashMap(id).isPresent();
}Inspect the HashMap lookup implementation and its JMH benchmarks for comparing search strategies. section 7.1.3

