Uploaded image for project: 'Tapestry'
  1. Tapestry
  2. TAPESTRY-2165

RecordUtils.iterateOverMatchingAttributes efficiency

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.1, 4.1.1, 4.1.2, 4.1.3, 4.1.5
    • Fix Version/s: 4.1.7
    • Component/s: Framework
    • Labels:
      None

      Description

      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 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; }

      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dcalde Daniel Caldeweyher
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: