[ 
https://issues.apache.org/jira/browse/WICKET-7045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17714026#comment-17714026
 ] 

ASF subversion and git services commented on WICKET-7045:
---------------------------------------------------------

Commit afd3b8f82255b4ddb1ae63f813a16c3bb5137e94 in wicket's branch 
refs/heads/wicket-9.x from Thomas Heigl
[ https://gitbox.apache.org/repos/asf?p=wicket.git;h=afd3b8f822 ]

WICKET-7045 PageParameter optimizations (#577)

* Do not allocate when checking for empty named parameters

* Do not allocate when checking for existence of named parameters

(cherry picked from commit d6dfa8b9ad4a6a39ee49d9503082251d1c16ce9b)


> 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: Minor
>
> 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)

Reply via email to