Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
9.12.0
-
None
Description
PageParameters.getNamedKeys allocates a new TreeSet for every invocation:
public Set<String> getNamedKeys() { if ((namedParameters == null) || namedParameters.isEmpty()) { return Collections.emptySet(); } Set<String> set = new TreeSet<>(); for (NamedPair entry : namedParameters) { set.add(entry.getKey()); } return Collections.unmodifiableSet(set); }
Most of the calls to the method do not actually need the contents of the set. They either check if the set is empty, or check if it contains a given key. The empty checks can directly use the underlying list of named parameters, while the contains checks could use iteration since the number of page parameters is likely limited.
The contains check is roughly 5-10 times faster for reasonably sized page parameters. The empty check is 50 times faster.
Benchmark Mode Cnt Score Error Units Benchmark.newHit thrpt 2 171106625,173 ops/s Benchmark.newMiss thrpt 2 139733394,987 ops/s Benchmark.newIsEmpty thrpt 2 1119518738,277 ops/s Benchmark.oldHit thrpt 2 25517811,801 ops/s Benchmark.oldMiss thrpt 2 25526261,487 ops/s Benchmark.oldIsEmpty thrpt 2 29757162,970 ops/s
Attachments
Issue Links
- links to