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
Currently, there is no cache mechanism in Illuminate\View\Compilers\Compiler::isExpired, so if you include a view 10,000 times in your output (very possible if you have a super modular design, or a table / row / cell set up with lots of rows), it will literally check if the file exists 10,000 times and execute filemtime 20,000 times (checking both target and source creation dates).
I ran into this when I discovered (using xdebug profiling) that the "isExpired" function is the biggest bottleneck I have on a datagrid I have created, were the "cell" blade on the lowest level of the blade is used many thousand times (our customers like to have a lot of rows visible at once)
I attempted to add a cache in Illuminate/View/Compilers/Compiler.php like so:
public function isExpired($path)
{
static $cache = [];
$compiled = $this->getCompiledPath($path);
if (isset($cache[$path])) {
return $cache[$path];
}
// If the compiled file doesn't exist we will indicate that the view is expired
// so that it can be re-compiled. Else, we will verify the last modification
// of the views is less than the modification times of the compiled views.
if ( ! $this->files->exists($compiled)) {
$cache[$path] = true;
return true;
}
$cache[$path] = $this->files->lastModified($path) >= $this->files->lastModified($compiled);
return $cache[$path];
}
Using xdebug, I can see that adding the cache dropped the time spent in this function dramatically.
Without cache: 43.46% of total time
With cache: 1.32% of total time
43% -> 1%!! it seems like adding a cache would be worth it for such a huge difference.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, there is no cache mechanism in Illuminate\View\Compilers\Compiler::isExpired, so if you include a view 10,000 times in your output (very possible if you have a super modular design, or a table / row / cell set up with lots of rows), it will literally check if the file exists 10,000 times and execute
filemtime
20,000 times (checking both target and source creation dates).I ran into this when I discovered (using xdebug profiling) that the "isExpired" function is the biggest bottleneck I have on a datagrid I have created, were the "cell" blade on the lowest level of the blade is used many thousand times (our customers like to have a lot of rows visible at once)
I attempted to add a cache in
Illuminate/View/Compilers/Compiler.php
like so:Using xdebug, I can see that adding the cache dropped the time spent in this function dramatically.
Without cache: 43.46% of total time
With cache: 1.32% of total time
43% -> 1%!! it seems like adding a cache would be worth it for such a huge difference.
Beta Was this translation helpful? Give feedback.
All reactions