New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thymeleaf 3: Is loading the template four times really necessary? #108
Comments
Thanks for raising this. Yes, the loading of a template 4 times seems totally unnecessary. At the time I added those, it was the only way I knew how to obtain a model from a template, not knowing that it went through all of these Thymeleaf methods to reach out to template resolvers and everything else. Now, I know how to pull out a sub-model from a model, so I'll be adding that to those areas you've identified. Just curious: since this goes through the template manager, does turning the Thymeleaf cache on stop the excessing loading? |
Each of those four loadings is done with a different cache key since the selector is included in the cache key. Of course, when the page is loaded the second time with caching turned on, we already have those four entries in the cache. |
The TemplateModel is Thymeleaf's immutable model type, and returned by the template manager. I'm making this more explicit so that, the next time I use this class, I can see that it is an actual fetch of the template, and as such, a potential performance penalty, as seen in #108.
Didn't think I'd be working on this for a while, but I came across something else that needed changes to how I fetch models, and so this got updated in the process 😁 I've just uploaded another 2.0.0-SNAPSHOT, so that should reduce the crazy amount of template fetching that you found. |
Thanks! Now I got #110 ;-) |
I'm checking the Snapshot implementation currently, and I found out that the template which is used to decorate (surround) our main template is loaded four times:
one time completely at DecoratorProcessor 92
one time with selector head at HtmlDocumentDecorator 72
one time with selector body at HtmlDocumentDecorator 101
one time with selector html at HtmlDocumentDecorator 119
Do you think that's necessary? Couldn't you clone the one loaded the first time? We have remote access for the template, so we have a little performance issue with that.
The text was updated successfully, but these errors were encountered: