[wp-trac] [WordPress Trac] #14429: Faster is_serialized
WordPress Trac
wp-trac at lists.automattic.com
Sun Oct 31 13:22:52 UTC 2010
#14429: Faster is_serialized
--------------------------+-------------------------------------------------
Reporter: sambauers | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 3.1
Component: Optimization | Version: 3.0
Severity: minor | Keywords: has-patch dev-feedback
--------------------------+-------------------------------------------------
Comment(by duck_):
Attached new patch with some improvements over 14429-strpbrk.9.patch:
* Incorporated Denis' suggestion to remove `.*` from regex for a, s, O
* Removed `strpos( 'adObis', $token )` since that will be caught by not
matching any of the cases in the switch statement
* Doesn't false-positive against `s:4:test;` (missing quotes around test)
Results from some quick profiling using xdebug across 10 front page loads
of a test site (measuring the 8610 calls to is_serialized):
{{{
14429.10.diff: 181555 microseconds
14429-strpbrk.9.patch: 189115 microseconds
trunk (strpbrk): 280283 microseconds
}}}
Though there are still some false-negatives (e.g. serialize(2.1E+200),
#9930) and false-positives (e.g. `b:5;`).
The only real way around this (as far as I can see) is by actually making
use of unserialize in the test. An interesting approach I've seen which
allows you to do this and not have to run unserialize twice (once for the
test and again if it's serialized) is [http://gist.github.com/217091
here]. Profiling a modified version of the code from that gist gave the
best results in this particular test, 147125 microseconds, but it would be
much slower over, for example, a million iterations of a small serialized
object. However, the first test is probably a better real world example
and if used right that doesn't matter since you're getting the
unserialized result back too.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14429#comment:21>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list