You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Memory usage can reach over 250MB caching template.
The function in craftcms/cms/src/services/TemplateCaches.php called includeElementQueryInTemplateCaches can be optimized reducing the memory usage to less than 15 Mb.
Suggestion
/** * Includes an element criteria in any active caches. * * @param Event $event The 'afterPrepare' element query event */publicfunctionincludeElementQueryInTemplateCaches(Event$event)
{
// Make sure template caching is enabledif ($this->_isTemplateCachingEnabled() === false) {
return;
}
if (!empty($this->_cachedQueries)) {
/** @var ElementQuery $elementQuery */$elementQuery = $event->sender;
$query = $elementQuery->query;
$subQuery = $elementQuery->subQuery;
$customFields = $elementQuery->customFields;
$elementQuery->query = null;
$elementQuery->subQuery = null;
$elementQuery->customFields = null;
// We need to base64-encode the string so db\Connection::quoteSql() doesn't tweak any of the table/columns names$serialized = base64_encode(serialize($elementQuery));
$elementQuery->query = $query;
$elementQuery->subQuery = $subQuery;
$elementQuery->customFields = $customFields;
$hash = md5($serialized);
gc_disable(); // disable automatic garbage collectorforeach ($this->_cachedQueriesas &$queries) {
$queries[$hash] = [
$elementQuery->elementType,
$serialized
];
gc_collect_cycles();
}
$queries = null; // release memory
unset($queries); // break the binding between variable name and variable contentgc_enable(); // enabling automatic garbage collector
}
}
Steps to reproduce
Mesure the memory usage of a non cached request with the enableTemplateCaching = true.
Additional info
Craft version: 3
PHP version: 7.0.12
The text was updated successfully, but these errors were encountered:
blasvicco
changed the title
Template cache need memory optimization.
BUG: Template cache memory exhausted.
May 18, 2018
Description
Memory usage can reach over 250MB caching template.
The function in
craftcms/cms/src/services/TemplateCaches.php
calledincludeElementQueryInTemplateCaches
can be optimized reducing the memory usage to less than 15 Mb.Suggestion
Steps to reproduce
enableTemplateCaching
= true.Additional info
The text was updated successfully, but these errors were encountered: