Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-10269

cache results of isResourceType()

    XMLWordPrintableJSON

Details

    Description

      I have code, which uses

      resourceResolver.isResourceType(Resource, String)

      very often to determine type information. I also observed, that the execution time of this method contributes a lot to the overall execution time.

      Also the number of unique resourcetypes which are going to be checked (resource.getResourceType, 1st parameter) is typically quite low; the same applies for the number of resourcetypes it is compared against. So it makes sense to cache the result of that method call in map which shares the lifetime of the ResourceResolver, as the result will never change during this lifetime. But during a refresh() or commit() this map can be cleared, so any changes in the RT hierarchy which might have happened will get effective.

      I have tested this approach already and it gives a significant speedup to my code (reduced execution time by 50%); of course this cannot be expected universally, as this is an extreme case, but it shows that there is indeed a bit of overhead.

      https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/43

      Attachments

        Issue Links

          Activity

            People

              joerghoh Joerg Hoh
              joerghoh Joerg Hoh
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 3.5h
                  3.5h