In light of discussion on a recently merged PR [1], I raised the question 'do we need to "reset" the accessible flag for reflective injectables (fields, methods, constructors)?'
The sole purpose of synchronized around the injection logic (including constructor instantiation) seems to surround properly resetting the accessible flag on the reflection element, and ensuring the element is accessible during the injection. It is likely worth the effort to determine if resetting that flag, and thus the accompanying synchronized, is really needed. As a reference, I searched Apache Felix for uses of setAccessible, as it also needs to be able to inject into non-public elements [2]. After browsing a handful of the non-test classes, I found none that do anything more than setAccessible(true). This leads me to believe that we are doing extra work in Sling Models that isn't really necessary. Removing synchronized could have a dramatic, positive impact on performance, especially for situations where there may be high contention (e.g. heavy model/submodel reuse, sharing a common super class, etc). If those synchronizations were removed, overall throughput will likely increase. Refs: [1]: https://github.com/apache/sling-org-apache-sling-models-impl/pull/11/files#r762409049 [2]: https://github.com/apache/felix-dev/search?q=setAccessible -Paul