Uploaded image for project: 'Shiro'
  1. Shiro
  2. SHIRO-566

CollectionUtils should use Collections wrappers of arrays if possible

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 1.2.4
    • 1.3.0
    • None
    • Any

    Description

      org.apache.shiro.util.CollectionUtils.asSet() and .asList() could use Collections wrappers for the passed-in elements. These are smaller and faster than copying the contents into other collections.

      The editability of the returned Collections is not required as currently it will return either an unmodifiable emptyList() / emptySet() or a modifiable ArrayList / LinkedHashSet. Ideally it would wrap the LinkedHashSet in unmodifiableSet and declare the immutability of the returned collections in the docs.

      In my use case for Shiro we create about 6000 - 7000 WildcardPermission objects per second. The great majority of them have a a list of parts with single subparts and thus don't need a proper LinkedHashSet created. This change improve the performance of our system by 10% under heavy load, mostly due to the reduced GC of temporary LinkedHashSet objects.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mattbishop Matt Bishop
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: