Jeff-Lewis / smarty-php

Automatically exported from code.google.com/p/smarty-php
0 stars 0 forks source link

Minor performance improvement #152

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a custom error_handler
2. Supply multiple directories
3. Use any template

What version of the product are you using? On what operating system?
3.1.14, Windows Vista and CentOS 6.3

Please provide any additional information below.
The filemtime() in Smarty_Resource->fileExists will cause the custom 
error_handler to be called. Regardless of whether the error_handler does 
anything, it causes call overhead. This can be improved by testing for 
is_file() first.

Change line #349 in smarty_resource.php from:
$source->timestamp = @filemtime($file);
to:
$source->timestamp = is_file($file) ? @filemtime($file) : false;

You could use file_exists() instead, but is_file() is faster and should be 
sufficient to catch all but rare cases which will be caught by filemtime() 
anyway.

This may only be useful if you have multiple template directories. I have on 
average about 5 paths specified and this small hack improved performance of the 
fetch() operation by ~18%.

Original issue reported on code.google.com by mart...@crmmailtech.nl on 12 Sep 2013 at 7:34

GoogleCodeExporter commented 9 years ago
Yep, you are right when you have a custom error_handler and muiltiple 
directories.

On the other hand benchmarking showed that $source->timestamp = 
@filemtime($file); is much faster if you have no error_handler. 

Maybe we should find a way to be able to switch it on or off.

Original comment by Uwe.Tews@googlemail.com on 14 Sep 2013 at 3:56

GoogleCodeExporter commented 9 years ago
Your patch is now in the SVN and will later be included in 3.1.15

Original comment by Uwe.Tews@googlemail.com on 1 Oct 2013 at 6:57