While this PHP extension is not actually a "requirement" for using Twig, it does help increase performance. Regardless, we should add a notice when it is not installed.

This is very similar to how we provided a notice when the PECL uploadprogress extension was not installed. The Twig C PHP extension helps improve rendering performance up to 15% for more complex templates.

See: http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension


#5 twig-c-ext-status-2160643-05.patch1.1 KBjhedstrom
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 92,306 pass(es). View


Cottser’s picture

Component: user interface text » theme system
Issue summary: View changes

Bumping this and changing "compilation" to "rendering", because the purpose of the C extension (at this time anyway) is to replace calls to TwigTemplate::getAttribute() (magic dot operator power) with a native C function (available to PHP).

jhedstrom’s picture

Status: Active » Needs review
Issue tags: +Performance
4.68 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 92,286 pass(es). View

This adds detection of the Twig C extension to the status report. Tagging 'Performance' since doing this will inform people that this is available as an option.

jhedstrom’s picture

1.1 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 92,281 pass(es). View

Oops, that had work from another issue.

dawehner’s picture

  1. +++ b/core/modules/system/system.install
    @@ -648,6 +648,22 @@ function system_requirements($phase) {
    +    $url = Url::fromUri('http://twig.sensiolabs.org/doc/installation.html#installing-the-c-extension')->toString();

    Are we really sure there is a value in doing that? It will really just output the string which comes in, right? We also link directly to https://www.drupal.org in other parts of the code.

  2. +++ b/core/modules/system/system.install
    @@ -648,6 +648,22 @@ function system_requirements($phase) {
    +    $requirements['twig_c_ext'] = [

    Any reason to not write a full name, so :twig_c_extension?

jhedstrom’s picture

1.61 KB
1.1 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 92,306 pass(es). View

1. Good point!
2. Fixed.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks nice now!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This is a normal task and usually I'd ask for a beta evaluation but considering this is only adding helpful information to the UI in a completely non disruptive fashion we're good to go. Committed 3b6e90d and pushed to 8.0.x. Thanks!

  • alexpott committed 3b6e90d on 8.0.x
    Issue #2160643 by jhedstrom, dawehener: Add status report "requirement"...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

msonnabaum’s picture

Status: Closed (fixed) » Needs work

Just found this new status message and I was surprised by it.

"Enabling the Twig C extension can greatly increase rendering performance" seems completely false to me. This implies to me that it will improve the performance of rendering a page, or executing templates at run time, which it will not. It's only an optimization for template rebuilding, which should be a rare event. Also, I'm not sure 15% qualifies as "greatly", if that number is even still correct.

Please correct me if I'm wrong, but it seems to me this message needs to be rephrased.

Cottser’s picture

Status: Needs work » Closed (fixed)

@msonnabaum that's a misunderstanding, some more details in this link (also in the IS) and below: http://derickrethans.nl/twig-extension.html

The Twig PHP extension replaces calls in the compiled template with native C functions. So it doesn't make template compilation faster but it should make template rendering (execution at run time) faster.

The improvement depends on how many dots in Twig you use in your Twig templates - when you go {{ foo.bar.baz.quux }} each of those dots needs to be resolved as array key, object property, method, setter, getter, etc. at runtime because the variable will change. That is what TwigTemplate::getAttribute() does and that is the slow part that the Twig C extension replaces with a faster native version.

I think if we want to tweak the wording that should be done in a follow-up, for example if we think "greatly" is too strong a word.

msonnabaum’s picture

Thanks Scott, that is exactly the clarification I needed.

anavarre’s picture