Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#10972 closed enhancement (fixed)

Improve sanitize_post() calling

Reported by: johanee Owned by:
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.9
Component: Performance Keywords: has-patch
Focuses: Cc:


http://core.trac.wordpress.org/changeset/11282 resulted in a 5% performance regression.

sanitize_post() is called on every get_post(), which is used almost everywhere such as in commonly-called template functions (the_title, get_permalink, etc.).

A better solution than reverting the commit is to call sanitize_post() once only for a post: before storing in wp_cache_add() and for wp_query->posts. Instead of for example 16 times for each post in default theme.

This patch restores the performance lost by changeset 11282.

Attachments (4)

posts-only-sanitize-once.patch (2.2 KB) - added by johanee 6 years ago.
Only sanitize_post() once
l10n-translation-noop-performance-2.patch (2.8 KB) - added by johanee 6 years ago.
Only sanitize_post() once, avoid double filtering
posts-only-sanitize-once-2.patch (2.4 KB) - added by johanee 6 years ago.
Only sanitize_post() once, avoid double filtering
10972.diff (2.7 KB) - added by ryan 6 years ago.

Download all attachments as: .zip

Change History (14)

@johanee6 years ago

Only sanitize_post() once

comment:1 @scribu6 years ago

  • Milestone changed from Unassigned to 2.9

comment:2 @scribu6 years ago

  • Summary changed from Changeset 11282 performance regression - and no need to sanitize_post more than once to Improve sanitize_post() calling

comment:3 @ryan6 years ago

Perhaps we can move the loop from _sanitize_the_posts() directly into WP_Query::get_posts(). That way it is run even if filters are suppressed and we avoid the pass by value overhead incurred by anything attached to a filter.

comment:4 @ryan6 years ago

See also the patch on #10801 which avoids extra filtering in some places.

comment:5 @johanee6 years ago

Updated patch:

  • Call sanitize_post directly from WP_Query::get_posts() instead
  • Also need to call it from get_pages()
  • Included sanitize_post check from #10801 to avoid double filtering

Did not include get_post() part of #10801 which looked strange and probably buggy. :)

@johanee6 years ago

Only sanitize_post() once, avoid double filtering

comment:6 @ryan6 years ago

That looks like the #10971 patch.

@johanee6 years ago

Only sanitize_post() once, avoid double filtering

comment:7 @johanee6 years ago

Oops. Here is the correct one.

@ryan6 years ago

comment:8 @ryan6 years ago

Revised slightly to avoid extra count() calls.

comment:9 @johanee6 years ago

Ok, looking good! Performance for 10972.diff

Average total page load time (ab -c 1 -n 100 http://example.org) for new 2.9.0-rare install

1 post front page
org: 49ms
fix: 47ms

10 post front page
org: 115ms
fix: 95ms

Numbers are stable.

comment:10 @ryan6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12062]) Improve sanitize_post() performance. Perform raw filtering only once. Add filter check to eliminate double filtering. Props johanee. fixes #10972 see #10801

Note: See TracTickets for help on using tickets.