Welcome to Geeklog Tuesday, December 10 2019 @ 11:07 pm EST
Geeklog Forums
Faster template processing
Status: offline
remy
Forum User
Full Member
Registered: 09/06/03
Posts: 150
Location:Rotterdam & Bonn

In the template class, the variables are substituted with a preg_replace, while all values must be manipulated to avoid 'bogus stripping'.
Following example does the same with a preg_replace_callback and speeds up the processing AND is recursive too. There is no need to neither process nor copying of (huge) arrays of vars and values.
Well, that's tested in my case: having many, many vars.
$regex = '/\{([-\.\w\d_\[\]]+)\}/';
$callback = function($matches) { return $this->substitute($matches[1]); };
$text = $this->get_var($var);
$text = preg_replace_callback($regex, $callback, $text);
}
There is no step for PHP to translate a lot of regexes, just one callback.
One can avoid the recursion when 'substitute' is replaced by 'get_var'.
Following example does the same with a preg_replace_callback and speeds up the processing AND is recursive too. There is no need to neither process nor copying of (huge) arrays of vars and values.
Well, that's tested in my case: having many, many vars.
PHP Formatted Code
protected function substitute($var) {$regex = '/\{([-\.\w\d_\[\]]+)\}/';
$callback = function($matches) { return $this->substitute($matches[1]); };
$text = $this->get_var($var);
$text = preg_replace_callback($regex, $callback, $text);
}
There is no step for PHP to translate a lot of regexes, just one callback.
One can avoid the recursion when 'substitute' is replaced by 'get_var'.
4
2
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 27/09/05
Posts: 1384
Always interested in speeding up the template class. Are you able to update the template class with these changes? You could do a pull request on our repository: https://github.com/Geeklog-Core/geeklog
One of the Geeklog Core Developers.
One of the Geeklog Core Developers.
3
3
Quote
Status: offline
remy
Forum User
Full Member
Registered: 09/06/03
Posts: 150
Location:Rotterdam & Bonn

Don't know pull.
The described function is a direct replacement for the function slow_subst.
I'm focussed on recursion, and the caching in template.class is hindering recursion in the logic extension syntax; i.e. if, loop, while. Blocks processing is a headache too.
I'm still experimenting.

The described function is a direct replacement for the function slow_subst.
I'm focussed on recursion, and the caching in template.class is hindering recursion in the logic extension syntax; i.e. if, loop, while. Blocks processing is a headache too.
I'm still experimenting.

2
3
Quote
Status: offline
Laugh
Site Admin
Admin
Registered: 27/09/05
Posts: 1384
Experiment away.
I use a lot of template variables and logic processing in my templates so any speed increase is excellent.
I will be working on Geeklog code again in September. If you have an updated template class by that point I can test and include it with the main code base, if it all checks out. Just remember we need to support PHP 5.6 (and higher).
One of the Geeklog Core Developers.

I use a lot of template variables and logic processing in my templates so any speed increase is excellent.
I will be working on Geeklog code again in September. If you have an updated template class by that point I can test and include it with the main code base, if it all checks out. Just remember we need to support PHP 5.6 (and higher).
One of the Geeklog Core Developers.
3
2
Quote
All times are EST. The time is now 11:07 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content