WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#17129 closed enhancement (fixed)

Speed up is_serialized_string()

Reported by: markjaquith Owned by: markjaquith
Priority: normal Milestone: 3.2
Component: Performance Version:
Severity: minor Keywords: reporter-feedback
Cc:

Description

is_serialized_string() uses an expensive regular expression. It should use substring peeking like is_serialized() does. In my tests, this offers a time reduction of about 26%.

Attachments (2)

17129.diff (699 bytes) - added by markjaquith 2 years ago.
17129.patch (756 bytes) - added by hakre 2 years ago.
Review

Download all attachments as: .zip

Change History (9)

markjaquith2 years ago

comment:1 greuben2 years ago

Edit: Oops, Ignore What I've said...

the last elseif can be changed to

elseif ( '"' !== $data[4] || '"' !== $data[$length-2] )
    return false;
Last edited 2 years ago by greuben (previous) (diff)

comment:2 markjaquith2 years ago

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

In [17779]:

Speed optimizations for is_serialized_string(). fixes #17129

comment:3 nacin2 years ago

  • Milestone changed from Awaiting Review to 3.2

hakre2 years ago

Review

comment:4 hakre2 years ago

  • Keywords reporter-feedback added

When I reviewed the changeset this is what came into my mind. I have not benchmarked so far if it's actually faster than the if / else approach.

comment:5 hakre2 years ago

Related: #14429

comment:6 hakre2 years ago

A note of caution: is_serialized_string() will return true for cases is_serialized() will return false. So both functions are not compatible with each other.

Related: #17375

Version 1, edited 2 years ago by hakre (previous) (next) (diff)

comment:7 hakre2 years ago

Related: #17445

Note: See TracTickets for help on using tickets.