Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-469

PassiveExpiringMap performance improvement and refreshing policy

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • 4.x
    • Map
    • None

    Description

      A copy from COLLECTIONS-467.

      Two remarks about current trunk implementation of PassiveExpiringMap.

      You should additionally keep the value of the next element timeout (the youngest timeout) in object field, so that you don't need to iterate through whole map to find elements for expiration on each call. It improves performance by calculating only simple if for most cases:

      public class PassiveExpiringMap {
        long youngestTimeoutMs = 0; // assert to have next timeout time for youngest element here always, or 0 if map is empty
        
        private void removeAllExpired(final long now) {
          if (youngestTimeoutMs>0 && youngestTimeoutMs<=now) {
            // do the cleanup
          }
        }
      }
      

      The second remark concerns the refreshing policy. As I can see there's no refreshing policy in current implementation, there should be at last two policies: NoRefresh (working as the current) and RefreshOnHit - which updates element expiration time when the element is "hit" (eg. by get()), so that the map always removes the least used resources.

      Attachments

        Activity

          People

            Unassigned Unassigned
            l0co l0co
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: