Performance: mapsToURI getting called multiple times

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Performance: mapsToURI getting called multiple times

Sergei Rahouski

I’ve spent some more time profiling Grails. This time I was focusing on page load times. The issue have been bothering me is that GSP pages on first load take much longer to load than subsequent loads.

 

I was surprised to see that most of the time it spends matching AntPath expressions.

 

We have a large application with over 500 controllers. What happens is DefaultGrailsControllerClass.mapsToURI method gets called many many times. That executes ant path matching. 500 controllers 10 actions each that gives us roughly 5000 (in reality 12200) antpath.match() call that chops and cuts strings left and right.

 

I tried to identify the reasons and found out that in *development* mode Grails does NOT cache URIs to controller classes.

 

if (Environment.getCurrent() != Environment.DEVELOPMENT) {
                uriToControllerClassCache.put(uri, controllerClass); 

}

 

This is unfortunate, but how big deal that is…. hard to tell.

 

But then I realized that if you use URLMappings to embed parameters in the URL that will have similar effect. Having large number of entities for example “contracts” in the database and using url mapping “/contract/:id” will give you large number of distinct URIs which will not fit in 10000 items uriToControllerClassCache cache . This will lead Grails to constantly go down development-mode route and do path matching. That doesn’t scale well and will lead to performance problems as your application grows.

 

Thoughts?