Thomas Heigl created WICKET-7045:
------------------------------------

             Summary: 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


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