[
https://issues.apache.org/jira/browse/WICKET-7045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17712765#comment-17712765
]
ASF GitHub Bot commented on WICKET-7045:
----------------------------------------
theigl opened a new pull request, #577:
URL: https://github.com/apache/wicket/pull/577
This PR avoids creating a `TreeSet` in `PageParameters.getNamedKeys()` when
we do not actually need the contents of the set.
The empty check is 50x faster. The contains check is 5-10x faster for page
parameters of a reasonable size.
If somebody is using page parameters with dozens or hundreds of elements, we
could still fall back to the `TreeSet`, but I highly doubt it.
https://issues.apache.org/jira/browse/WICKET-7045
> Avoid allocations in PageParameters.getNamedKeys
> ------------------------------------------------
>
> Key: WICKET-7045
> URL: https://issues.apache.org/jira/browse/WICKET-7045
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-core
> Affects Versions: 9.12.0
> Reporter: Thomas Heigl
> Assignee: Thomas Heigl
> Priority: Major
>
> PageParameters.getNamedKeys allocates a new TreeSet for every invocation:
> {code:java}
> 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);
> }
> {code}
> 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.
> {noformat}
> 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
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)