oyejorge / less.php

less.js ported to PHP.
http://lessphp.typesettercms.com
Apache License 2.0
657 stars 2 forks source link

Optimize cache generation speed and footprint #368

Open Cerdic opened 5 years ago

Cerdic commented 5 years ago

A bottleneck in cache generation is the computation of cache_string due to the number of arguments needed to be exported. Examining cache I saw that $currentFileInfo is over and over repeated in the cache.

This pull request change the $currentFileInfo property from Less_Environment in a static property being used globally in all Less/Tree/xxx instead of duplicating the same property value everywhere.

The static property is poped and pulled before and after each inclusion, that was already done.

*Tree/Comment, Tree/Directive, Tree/Mixin/Call and Tree/Selector are keeping a copy of the reference flag of $currentFileInfo

Thus the cache footprint is divided by 8 on a real case life (of course depending of the currentFileInfo content) and the time consumption for generating cache_string property is also reduced