Avoid extra calls to Smarty::getTemplateDir #30280
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
They end up doing lots of redundant path normalization. Make sure we only register each directory once per process, even if we are resetting the Config singleton multiple times (e.g. for locale swapping).
Overview
Stop slowdowns caused by lots of redundant calls to internal smarty functions.
Before
We noticed long-running processes with template rendering would slow down over time, to the point where rendering a single email would take 10 sec. This happened when using Smarty 3 or 5, but not with Smarty 2.
After
Long-running processes with rendering do not slow down.
Technical Details
Profiling showed most of the time in the Smarty::_realpath function, called from Smarty::_normalizeTemplateConfig. It turns out just calling getTemplateDir triggers this over and over again. We are switching locales during the long-running process to render different language emails, so the config hooks are running and re-registering template directories.