Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Auth Core 1.1.8
-
None
Description
When adding lot of paths, which need authentication, to the SlingAuthenticator, we encourage long times when the execution seems to starve at the PathBasedHolderCache.addHolder() method.
"FelixStartLevel" - Thread t@21 java.lang.Thread.State: RUNNABLE at java.util.ComparableTimSort.sort(Unknown Source) at java.util.ComparableTimSort.sort(Unknown Source) at java.util.Arrays.sort(Unknown Source) at java.util.Collections.sort(Unknown Source) at org.apache.sling.auth.core.impl.PathBasedHolderCache.addHolder(PathBasedHolderCache.java:68) at org.apache.sling.auth.core.impl.SlingAuthenticator$SlingAuthenticatorServiceListener.registerService(SlingAuthenticator.java:1511) at org.apache.sling.auth.core.impl.SlingAuthenticator$SlingAuthenticatorServiceListener.addService(SlingAuthenticator.java:1528) at org.apache.sling.auth.core.impl.SlingAuthenticator$SlingAuthenticatorServiceListener.serviceChanged(SlingAuthenticator.java:1494) locked <643be70> (a java.util.HashMap) at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:932) at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:793) ...
obviously the problem is the sorting of the ArrayList "byPathList" in the PathBasedCacheHolder.addHolder() method; this ArrayList is always taken from the already present cache, and then sorted again. We you add some tens of thousands items to this list, we might into a n^2 complexity.
Would it be possible to replace this implementation with something more performant, which benefits from the fact, that the byPathList is already sorted; or have a better datastructure (TreeSet?), which has the semantics we need?