Blade laravel and the performance

3

In Laravel , we usually use Blade to be able 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?>

Any doubts that have arisen are:

  • Does Laravel have to convert Blade to a valid PHP code, using regular expressions and the like, can not this result in performance loss?

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

asked by anonymous 01.10.2015 / 14:19

2 answers

8
  

Does Laravel have to convert the Blade to a valid PHP code, using regular expressions and the like, can not this imply a loss of performance?

Performace loss 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 executions will be made on top of that pure php file, also possible to cache that file. >

  

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

There are already too many php developers worrying about performance. Most of the time worry about writing human-readable code and optimizing only system bottlenecks, one possible solution is to use cache.

    
01.10.2015 / 14:53
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, unless you change the view Blade again, because the parsing views cache is based on the modification date of the Blade file.

    
03.03.2016 / 02:11