Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a notice for multiple twig renders #49

Merged
merged 1 commit into from Sep 12, 2016

Conversation

NielsdeBlaauw
Copy link
Member

Using clarkson_template::render_twig in a foreach
is a lot more expensive than including a partial in
a twig template, which is the most common use-case.

This user notice allows for easier tracking of this
performance bottleneck.

The test exsits of this code, common in some current projects:

    public static function getItems(){
      $clarkson_templates = \Clarkson_Core_Templates::get_instance();
      $path = get_template_directory() . '/templates/title.twig';

      $html = '';

      $items = self::get_many(array('posts_per_page'=>100));
      foreach($items as $item){
        $data = array("post"=>$item);
        $html .= $clarkson_templates->render_twig( $path, $data, true);
      }

      return $html;
    }
{{ getItems() }}

Versus

    public static function getItems(){
      return self::get_many(array('posts_per_page'=>100));
    }
{% for item in getItems() %}
  {% include 'title.twig' with {'post':item} %}
{% endfor %}

Multiple render_twig calls
Requests per second: 1.44 #/sec

Single render_twig call with includes
Requests per second: 3.22 #/sec

mutiple_render.ab.txt
single_render.ab.txt

Using clarkson_template::render_twig in a foreach
is a lot more expensive than including a partial in
a twig template, which is the most common use-case.

This user notice allows for easier tracking of this
performance bottleneck.
@jmslbam jmslbam merged commit f7bcf85 into master Sep 12, 2016
@jmslbam jmslbam deleted the feature/warn-multiple-twig-renders branch September 12, 2016 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants