[wp-trac] [WordPress Trac] #35025: Performance regression in comments_template in 4.4

WordPress Trac noreply at wordpress.org
Sat Dec 12 03:37:09 UTC 2015

#35025: Performance regression in comments_template in 4.4
 Reporter:  rogerhub           |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  4.4.1
Component:  Comments           |     Version:  4.4
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:  performance
Changes (by boonebgorges):

 * keywords:   => reporter-feedback


 Hi @rogerhub - Thanks for the report, and welcome to Trac!

 When the system works the way it was designed in 4.4,
 `$comment->get_children()` should result in no extra database queries,
 when called on comments that were fetched using `WP_Comment_Query` with
 `'hierarchical' => 'threaded'`. Here's the rundown:

 1. `comment_template()` calls `WP_Comment_Query` with `'hierarchical' =>
 'threaded'`. https://core.trac.wordpress.org/browser/tags/4.4/src/wp-
 2. `WP_Comment_Query::get_comments()` then calls the `fill_descendants()`
 method https://core.trac.wordpress.org/browser/tags/4.4/src/wp-includes
 3. `fill_descendants()` does only a single DB query for each hierarchy
 level across all located comments. In your case, this should mean just two
 queries: one for the top-level comments (ie, all of them), and then one
 for children of those comments (should return none, at which point db
 queries should stop)
 4. When `fill_descendants()` then builds the comment tree, it marks each
 comment with the `populated_children` flag.
 5. When `populated_children` is set, the `get_children()` method of
 `WP_Comment` should *not* do a database query:
 comment.php?marks=290-296#L279 See [34730].


 So, that's how it's supposed to work. (I'm going to attach a unit test
 that demonstrates that what I've described above is working, at least in
 the simple case.) If it's not working for you, it must be short-circuiting
 at one of these steps. With the above sketch in mind, do you think you
 could do some more debugging to see at which point the process is failing?

Ticket URL: <https://core.trac.wordpress.org/ticket/35025#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list