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

The Optimizer is slow in loop #84

Open
char101 opened this issue Jul 20, 2021 · 2 comments
Open

The Optimizer is slow in loop #84

char101 opened this issue Jul 20, 2021 · 2 comments

Comments

@char101
Copy link

char101 commented Jul 20, 2021

Hi,

When executed in a loop (actually when using phug inside an event-based framework like workerman), the performance of the optimizer is slow (6ms when compared to Fenom 0.1ms).

This can be improved by caching the 2nd parameter to isExpired at https://github.com/phug-php/phug/blob/master/src/Phug/Phug/Phug/Optimizer.php#L130.

In my test, caching the 2nd parameter of isExpired reduced the execution time from 6ms to 0.6ms. Still slower than Fenom's 0.1ms.

The remaining difference of 0.5ms I assume is because Fenom compiles template to an anomyous function + echo compared to pug which uses extract and include.

@kylekatarnls
Copy link
Member

kylekatarnls commented Jul 20, 2021

Hello 👋

Is up_to_date_check set to false? (It should in production).

If it is then the problem is likely the hasExpiredImport chack and I guess it should be skipped to when up_to_date_check === false.

@char101
Copy link
Author

char101 commented Jul 20, 2021

Looking at the code it seems that getSourceAndCachePaths is still called whether up_to_date_check is set to true or false. In my profiling data, getSourceAndCachePaths takes about 4.6ms.

This is the options I used in my profiling

$options  = [
    'paths' => [__DIR__],
    'php_token_handlers' => [T_VARIABLE => null],
    'cache_dir'          => __DIR__.'\\phug',
    'up_to_date_check' => false,
    'enable_profiler'  => false,
];

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

No branches or pull requests

2 participants