sonatype/nexus-oss — pull request #229 by mcculls (2013-11-06 02:07:53+00:00)
Title: [REVIEW] NXCM-5448: improve permissions performance

Contains 3 improvements:

1. Cache WildCardPermission hashCode (the hash is fixed after construction and is non-trivial to compute)
2. Resolve role permissions under single read-lock, rather than repeatedly take and drop it multiple times
3. Add memory-sensitive cache to the XML permissions resolver to avoid repeatedly resolving same role

Note the cache in 3. is invalidated by either the AuthorizationConfigurationChanged / SecurityConfigurationChanged events. One outstanding question is if we should also invalidate the cache when the AbstractConfigurationManager cache is rebuilt (happens when a DynamicSecurityResource, such as staging, returns isDirty=true).

On the one hand the current DynamicSecurityResources only add/remove elements, rather than update existing elements, which means (afaict) cached results will still be correct. It's more that some elements will no longer be referenced, which is ok as it's a weak value map so that mapping will then be evicted.

If we did decide to invalidate the resolver cache when the AbstractConfigurationManager cache was rebuilt then we can simply add `eventBus.post(new AuthorizationConfigurationChanged());` after the new EnhancedConfiguration has been created (just outside of the synchronized block if we want to minimize contention/locking pitfalls). We could also create a new event type (such as ConfigurationManagerRebuilt) if we were concerned about sending out additional AuthorizationConfigurationChanged events and wanted to limit the AbstractConfigurationManager rebuild event to our new resolver cache.