Problem/Motivation
There is some generalized logic in twig_render_template that does some extra work during normal rendering to support development rendering. This is not strictly necessary though.
Since this is a hot path it makes sense to have it as efficient as possible.
Steps to reproduce
Proposed resolution
Move all of the debug logic into the debug switch so the "production" path is optimized.
Remaining tasks
Benchmarks?
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3192830
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- reapply
compare
- 3192830-twigrendertemplate-micro-optimization
changes, plain diff MR !8275
Comments
Comment #2
neclimdulAdmittedly, there isn't a lot of internal time in this method so this is far from a high priority optimization but some basic synthetic tests showed something like a 25% improvement in the internal time of the method. Nice! Since a bulk of the logic is in the implode call that makes sense.
Comment #7
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Tagging for a reroll for 10.1.x
Tagging for subsystem maintainer of the theme layer to get their input
But if the logic is for development and doesn't interfere with the development functionality sounds like a good clean up.
Thanks!
Comment #8
_utsavsharma commentedReroll for 10.1.x.
Comment #9
neclimdulThe code is a bit different because of Twig 3 which broke the original patch. Probably just needs a rewrite not a reroll or maintainer review.
Comment #10
neclimdulNot so big a change it turns out. Here's a patch that should work.
Comment #11
smustgrave commentedThanks for the quick turnaround!
Did a quick test on Drupal 10.1.x on a standard install during debug on in my development.services.yml file
And debugging still works.
Comment #15
neclimdulreroll in MR
Comment #16
andypostnice clean-up!
Comment #17
longwaveNot convinced this is really going to make any measurable difference in the real world, but it makes the code a bit easier to read.
Backported to 10.3.x as a cleanup with no functional changes.
Committed and pushed 0ba6b793c6 to 11.x and 1eac567fbb to 11.0.x and d7549f3c3a to 10.4.x and ffdafb02cd to 10.3.x. Thanks!
Comment #22
longwaveComment #24
neclimdulNice!
Yeah, probably not measurable from a wall clock perspective with current PHP performance hence the title. However, it removes one assignment, one function call to implode, and the admittedly trivial string concats implode is doing from every twig_render. This means on a stock Drupal install it saves 54 function calls and assignments on an uncached request to the frontpage so its at least measurable from that metric. Since most sites are probably more complex then that and as you said its actually a bit cleaner it seemed worth while.