Ticket #5325 (closed defect: fixed)

Opened 6 months ago

Last modified 6 months ago

sanitize_post and sanitize_post_field are very expensive no-ops

Reported by: Quandary Assigned to: anonymous
Priority: normal Milestone: 2.3.2
Component: Optimization Version: 2.3.1
Severity: major Keywords: has-patch
Cc:

Description

Simple, commonly-called template functions (the_title, get_permalink, etc.) are all channeled through the get_post function. While get_post implements caching, it caches content before it's been filtered, not after. This means that sanitize_post is called for each and every call to get_post.

I loaded a test page 5 times in a test configuration that had 86 calls to get_post (mostly via get_the_title and get_permalink). Instrumentation results from APD indicate that fully 8-15% (~9.5% avg.) of the page generation time was spent in sanitize_post and sanitize_post_field, even though nearly all of the calls were for "raw" data, and no filtering was actually taking place. I added a simple early bail-out to bypass the no-op actions, and this reduced the hit to .1-.2% across another 5 page loads (no, that's not a typo ;).

I'm attaching a patch to fix this bug, but this is only the immediate problem (get_post appears to be called with "raw" way more frequently then with "display"). Opening another bug on the filtering implementation may be warranted.

Attachments

do_nothing_faster.diff (0.6 kB) - added by Quandary on 11/07/07 03:57:25.
Be almost two orders of magnitude faster at doing nothing.

Change History

11/07/07 03:57:25 changed by Quandary

  • attachment do_nothing_faster.diff added.

Be almost two orders of magnitude faster at doing nothing.

11/07/07 03:59:05 changed by Quandary

  • keywords set to has-patch.

11/07/07 06:20:09 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [6321]) Skip sanitization altogether for raw context. Props Quandary. fixes #5325

11/07/07 06:21:01 changed by ryan

  • status changed from closed to reopened.
  • resolution deleted.

Thanks. Applied to trunk. I also did this for sanitize_term. Nominating for 2.3 inclusion.

11/07/07 06:28:46 changed by ryan

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [6322]) Skip sanitization altogether for raw context. Props Quandary. fixes #5325 for 2.3