Portable blade and performance

Asked

Viewed 357 times

4

In the Laravel, we usually use the Blade in order to write a view.

Example:

@unless($variable)
<p>Nenhum dado encontrado</p>
@else
   @foreach($variable as $v)
     <p>{{ $v }} </p>
   @endforeach
@endunless

This code is "compiled" for:

<?php if (! ($variable)): ?>
    <p>Nenhum dado encontrado ?>
<?php else: ?>
     <?php foreach($variable as $v): ?>
     <p>{{ $v }} </p>
     <?php endforeach ?>
<?php endif?>

Some doubts that have arisen are:

  • The fact that the Laravel have to convert the Blade for a valid PHP code, using regular expressions and the like, this must not result in a loss of performance?

  • I should be more concerned with the ease of writing the code than with the performance in such cases?

2 answers

9


The fact that Laravel has to convert Blade to valid PHP code, using regular expressions and the like, cannot result in a loss of performance?

Loss of performace compared to what? template engines usually work as follows the first run it reads the template file and translates to pure php creating a new file, the other runs will be made on top of that pure php file, also possible to cache that file.

I must worry more about the ease of writing the code than with the performance in these cases?

There are already too many php programmers worrying about performance. Most of the time worry about writing human-readable code and optimise only system bottlenecks, one possible solution is caching.

3

This only happens the first time. After that, a file already parsed and converted to php code is generated and stays there in the Storage folder. So this parsing is not done every time, except if you change the view Blade again, because the parsed view cache is based on the file modification date Blade.

  • 1

    +1 grandson. I forgot to add this information to the question. This information is welcome ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.