This is a bug in Drupal 7 and Drupal 8.
$variables['created'] = format_date($comment->created);
$variables['changed'] = format_date($comment->changed);
The template provided by comment module renders neither of these, but format_date() is very expensive when called up to 600 times per page.
One obvious fix which should be backportable to Drupal 7 would be to only format the date once if $comment->change and $comment->created are the same timestamp.
For Drupal 8 we should look at whether Twig will let us take these out of generic preprocess and lazy-generate the variables based on the compiled template (i.e. it's supposed to know whether specific variables are used or not, so there shouldn't be a need to front-load things that are never printed). If not, let's just stop preparing those variables and let people use their own preprocess in custom themes if they want to.
Comment | File | Size | Author |
---|---|---|---|
#4 | comment-1857956-4.patch | 988 bytes | David_Rothstein |
#1 | comment_1857956.patch | 1.79 KB | catch |
Comments
Comment #1
catchHere's the backwards-compatible version.
Comment #2
plachLooks sensible to me as a stop-gap fix, altough I'd prefer a ternary here :)
I don't think this needs tests.
Comment #3
Dries CreditAttribution: Dries commentedMakes sense. Committed to 8.x. Moving to 7.x for Angie to commit.
Comment #4
David_Rothstein CreditAttribution: David_Rothstein commentedLooks reasonable to me, but the patch didn't remotely apply to Drupal 7. Rerolled, but it looks like only half of it may actually be relevant in D7.
Is this really a big enough performance improvement to be considered "major"?
Comment #5
plachLooks good.
Comment #6
webchickIn D7, no, I don't think so. It's a much bigger deal in D8 with CMI.
Comment #7
David_Rothstein CreditAttribution: David_Rothstein commentedCommitted to 7.x - http://drupalcode.org/project/drupal.git/commit/3d169b3