Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP

Home Page:http://jade.talesoft.codes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I check if cache is working? Because Tale-Jade is slow.

YamiOdymel opened this issue · comments

2016-07-14 12 29 27

I'm using Tale-Jade as my main template engine (currently deploy on C9 IDE),

when I need to generate the posts, I do something like (example):

foreach($posts as $post)
    $html .= $renderer->render('post-tpl', ['foo' => 'bar']);

And Tale-Jade took 5 seconds to render 20 posts,

it looks like Tale-Jade still scans for the tokens when the template has already been cached (see the picture below).

2016-07-14 12 37 13

And if I add an each loop in my template instead of looping the renderer it self:

$html = $renderer->render('post-tpl', ['data' => [['foo' => 'bar'], 
                                                     ['foo' => 'bar'], 
                                                     ['foo' => 'bar']]]);

It took me 0.8 seconds to render the 20 posts (It's still slow though),

is there any way to check if the cache is working or not?

Because I felt like Tale-Jade is generating the cache but never use them.

Sure, you can always just check the Last Modified times of the cached PHTML files.

If they change, Tale Jade re-cached.

Normally it directly checks if the cached file exists and is in range of the TTL, then it loads it.

Take a look at the caching logic here

In line 173 the actual compilation happens, unless it can be rendered directly because it exists already.

Try to debug it with some var_dumps, I'll do the same and we'll see if there's some problem.

Okay, I think the performance problem can be solved by upgrading PHP 5.6 to PHP 7.

Render 20 posts (each loop in the template file) now took me 0.05 seconds only,

PHP 7 is really fast .. and thanks for hinting the caching logic code (I couldn't find it with cache keyword yesterday)

in my past experience, using filemtime to check the file is really slow,

I have done a simple template engine before, and it was used filemtime to check the cache,

with filemtime my template engine took 1.733 seconds to render the posts,

but if I remove filemtime, it took 0.293 seconds only,

maybe you can remove the TTL feature (not sure how to explain it),

and I don't understand why should we re-render the template file if the template file isn't changed.

EDIT: After I installed XDebug for PHP 7.0, the performance problem still exists..

What do you mean with removing the TTL feature?

The TTL is the TimeToLive. When Tale Jade renders a file, the filemtime is set on that file and the engine is using that exact same file until the difference of the current time and the filemtime (the time that file lived already) is higher than the TTL.

The filemtime check is required for caching itself. Everything else would result in temporary files or something alike that would bring in even more overhead.

If you have an idea how to make that caching process faster, tell me :)

The only way to check if a file has been changed is by checking the filemtime (or doing CRC checks and storing them somewhere etc., but that would cost even more performance) :)

I'll set up some benchmarks as soon as I get to it.

After a month, that's my bad to said that Tale-Jade is slow,

the problem cause the slow performance is because I installed XDebug,

and I thought that you used some other conditions to check the cache is available or not,

that's the reason why I asked you to remove the TTL check,

not really offensive, Tale-Jade is fast without XDebug.