You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Andreas Andreou (JIRA)" <de...@tapestry.apache.org> on 2008/02/27 18:23:51 UTC

[jira] Updated: (TAPESTRY-2165) RecordUtils.iterateOverMatchingAttributes efficiency

     [ https://issues.apache.org/jira/browse/TAPESTRY-2165?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andreas Andreou updated TAPESTRY-2165:
--------------------------------------

    Fix Version/s:     (was: unspecified)
                   4.1.6

> RecordUtils.iterateOverMatchingAttributes efficiency
> ----------------------------------------------------
>
>                 Key: TAPESTRY-2165
>                 URL: https://issues.apache.org/jira/browse/TAPESTRY-2165
>             Project: Tapestry
>          Issue Type: Improvement
>          Components: Framework
>    Affects Versions: 4.1, 4.1.1, 4.1.2, 4.1.3, 4.1.5
>            Reporter: Daniel Caldeweyher
>            Priority: Minor
>             Fix For: 4.1.6
>
>
> The current implementation of RecordUtils.iterateOverMatchingAttributes is not very efficient as it iterates over all session attributesnames and check name.startWith(prefix) for every single one, basically an O(n) complexity. Given an app with a lot of pages each with multiple persisted properties this is not the best approach, considering that WebSession.getAttributeNames() returns a sorted list of strings. Because of this we can improve efficiency through binary search and shortcutting the search once we have passed the last prefix-matching attribute. Just replace the current iterateOverMatchingAttributes code:
>         String prefix = strategyId + "," + applicationId + "," + pageName + ",";
>         Iterator i = session.getAttributeNames().iterator();
>         while (i.hasNext()) {
>             String name = (String)i.next();
>             if (name.startsWith(prefix)) callback.handleAttribute(session, name);
>         }
> with:
>         String prefix = strategyId + "," + applicationId + "," + pageName + ",";
>         List sessionAttributeNames = session.getAttributeNames(); //sorted
>         int pos = Collections.binarySearch(sessionAttributeNames, prefix);
>         if(pos < 0) {
>         	pos = (-pos) - 1;
>         }
>         Iterator i = sessionAttributeNames.listIterator(pos);
>         while (i.hasNext()) {
>             String name = (String)i.next();
>             if (name.startsWith(prefix)) {
>                 callback.handleAttribute(session, name);
>             } else {
>             	break;
>             }
>         }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org