playframework/playframework — pull request #2628 by jroper (2014-08-28 05:30:20+00:00)
Title: Java templates slow loading language from config

Java templates are slower than Scala templates. A lot of the slowness (10-20%) seems to be because Java templates load language settings from the app config, whereas Scala templates use the JVM default language. (See #816 for a discussion of which is the correct approach.)

Below we can see that a lot of Java's slowness is caused by accessing the app config multiple times on each render. Config access seems to be really slow. A fix would be to cache the language after it is loaded from the config.

````
+-------------------------------------------------------------------------------+-----------------+
| Name | Time (ms) |
+-------------------------------------------------------------------------------+-----------------+
| +---play.api.Configuration.getString(String, Option) | 39,867 100 % |
| | | |
| +---play.api.Play$.langCookieName(Application) | 25,392 64 % |
| | | | |
| | +---play.api.Play.langCookieName(Application) | |
| | | | |
| | +---play.Play.langCookieName() | |
| | | | |
| | +---play.mvc.Http$Context.lang() | |
| | | | |
| | +---play.mvc.Http$Context$Implicit.lang() | |
| | | | |
| | +---play.core.j.PlayMagicForJava$.implicitJavaLang() | |
| | | | |
| | +---views.html.index$$anonfun$apply$1.apply() | |
| | | | |
| | +---views.html.index$$anonfun$apply$1.apply() | |
| | | | |
| | +---views.html.helper.form$.apply(Call, Seq, Function0) | |
| | | | |
| | +---views.html.index$.apply(Form) | |
| | | | |
| | +---views.html.index$.render(Form) | |
| | | | |
| | +---views.html.index.render(Form) | |
| | | |
| +---play.api.i18n.Lang$.availables(Application) | 14,475 36 % |
| | | |
| +---play.api.i18n.Lang$.preferred(Seq, Application) | |
| | | |
| +---play.api.i18n.Lang.preferred(Seq, Application) | |
| | | |
| +---play.i18n.Lang.preferred(List) | |
| | | |
| +---play.mvc.Http$Context.lang() | |
| | | |
| +---play.mvc.Http$Context$Implicit.lang() | |
| | | |
| +---play.core.j.PlayMagicForJava$.implicitJavaLang() | |
| | | |
| +---views.html.index$$anonfun$apply$1.apply() | |
| | | |
| +---views.html.index$$anonfun$apply$1.apply() | |
| | | |
| +---views.html.helper.form$.apply(Call, Seq, Function0) | |
| | | |
| +---views.html.index$.apply(Form) | |
| | | |
| +---views.html.index$.render(Form) | |
+-------------------------------------------------------------------------------+-----------------+
````