Skip to content
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

Closed
tobiasflohre opened this issue May 23, 2016 · 4 comments
Closed
Assignees

Comments

@tobiasflohre
Copy link

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.

@ultraq ultraq added this to the Thymeleaf Layout Dialect 2.0 milestone May 24, 2016
@ultraq ultraq self-assigned this May 24, 2016
@ultraq
Copy link
Owner

ultraq commented May 24, 2016

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?

@tobiasflohre
Copy link
Author

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.
Thanks for adressing this! Tell me when it's included in the latest snapshot :-)

ultraq added a commit that referenced this issue May 29, 2016
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.
ultraq added a commit that referenced this issue May 29, 2016
@ultraq
Copy link
Owner

ultraq commented May 29, 2016

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.

@ultraq ultraq closed this as completed May 29, 2016
@tobiasflohre
Copy link
Author

Thanks! Now I got #110 ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants