[wp-hackers] json_encode/decode VS serialization

Andrew Nacin wp at andrewnacin.com
Sat May 21 04:42:04 UTC 2011


On May 21, 2011 12:18 AM, "Nathan Rice" <ncrice at gmail.com> wrote:
>
> Now that WordPress 3.2 will support only PHP5+, is there any merit in
> possibly starting to store arrays of data in the database via json_encode
/
> json_decode, instead of PHP serialized?

No.

> I've read conflicting reports about speed improvements, one even
suggesting
> that json_encode was slower than serialize, but json_decode was faster
than
> unserialize. [1]
>
> Has anyone done any research into this, and is there any chance (assuming
> reads would be faster with json_decode) that WordPress would switch to
this
> method over (un)serialize? Seems like it would at least be worth some
> consideration.

No. Serialized data is the proper representation of PHP variables. JSON
would be lossy especially when it comes to objects.

Changing this would also introduce backwards compatibility concerns, thus no
real performance gain. Additionally, if you're looking for performance
benefits, I'd look elsewhere - like the queries themselves.

Nacin


More information about the wp-hackers mailing list