Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#10972 closed enhancement (fixed)

Improve sanitize_post() calling

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

Description

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 15 years ago.
Only sanitize_post() once
l10n-translation-noop-performance-2.patch (2.8 KB) - added by johanee 15 years ago.
Only sanitize_post() once, avoid double filtering
posts-only-sanitize-once-2.patch (2.4 KB) - added by johanee 15 years ago.
Only sanitize_post() once, avoid double filtering
10972.diff (2.7 KB) - added by ryan 15 years ago.

Download all attachments as: .zip

Change History (14)

@johanee
15 years ago

Only sanitize_post() once

#1 @scribu
15 years ago

  • Milestone changed from Unassigned to 2.9

#2 @scribu
15 years ago

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

#3 @ryan
15 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.

#4 @ryan
15 years ago

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

#5 @johanee
15 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. :)

@johanee
15 years ago

Only sanitize_post() once, avoid double filtering

#6 @ryan
15 years ago

That looks like the #10971 patch.

@johanee
15 years ago

Only sanitize_post() once, avoid double filtering

#7 @johanee
15 years ago

Oops. Here is the correct one.

@ryan
15 years ago

#8 @ryan
15 years ago

Revised slightly to avoid extra count() calls.

#9 @johanee
15 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.

#10 @ryan
15 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.