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
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | twig-c-ext-status-2160643-05.patch | 1.1 KB | jhedstrom |
Comments
Comment #1
star-szrBumping 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).
Comment #2
jhedstromThis 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.
Comment #3
jhedstromOops, that had work from another issue.
Comment #4
dawehnerAre 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.
Any reason to not write a full name, so :twig_c_extension?
Comment #5
jhedstrom1. Good point!
2. Fixed.
Comment #6
dawehnerLooks nice now!
Comment #7
alexpottThis 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!
Comment #10
msonnabaum commentedJust 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.
Comment #11
star-szr@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 whatTwigTemplate::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.
Comment #12
msonnabaum commentedThanks Scott, that is exactly the clarification I needed.
Comment #13
anavarreFiled #2568247: Remove the Twig C extension requirement as it needs to be proven it's still relevant for modern PHP versions to change the wording.