Details
Description
Doing stress tests on a JSF application we have noticed some contention.
14% of the time that the threads are blocked is due to calls to ClassLoader#getResource(String). Such calls comes from method org.apache.myfaces.shared.resource.ResourceImpl#getUrl(). (see attached image)
Viewing the code of the method ResourceImpl#getURL(), it is always calculating the URL of the resource through the ResourceLoader. This, in turn, ends up calling the method ClassLoader#getResource(String).
public URL getURL()
{ return getResourceLoader().getResourceURL(_resourceMeta); }Since the resulting URL will not change during the life of the resource instance, it could be stored in an instance variable and thus prevent subsequent calls to this method end up calling the ClassLoader.
private URL _url;
public URL getURL()
{
if (_url == null)
return _url;
}
With this change applied we obtained a performance improvement between 14% and 119% of throughput, depending on the complexity of the rendered view.