Tech Blog

Faster alternative to CFWDDX - java serialize

Posted At : May 7, 2007 11:24 PM

As part of looking at implementing the memcached client for CF I've been looking at using the native Java serialize methods instead of the cfwddx serialization that I put in first time to get it to work.

With a bit of help from Max Nyman I've created some tags to handle java serialization in a similar manner to cfwddx.

Some rough benchmarks on this using an array of numbers between 100 and 10,000 elements and repeating between 100 and 10000 times resulted in the following general observations:

JavaSerialize on average took 60% of the execution time of cfwddx for a serialize and deserialize operation.

In addition to this - the data length was typically 60% of the wddx length. This has significant benefits when it is used for caching in memory. It means you can fit more data in the same amount of ram or use less ram!

The tag is available here

To serialize from CF use the following:

<cfimport prefix="util" taglib="/au/com/lynchconsulting/customtags/util/">
<util:javaSerialize action="fromCF" input="#cfObj#" output="serialized">

To serialize to CF use the following:

<cfimport prefix="util" taglib="/au/com/lynchconsulting/customtags/util/">
<util:javaSerialize action="toCF" input="#serialized#" output="cfObj">

Note that fromCF function returns a binary object - which would need to be converted to base64 if you want to transfer them via a form submission.

Another Note - the customtag does add some overhead, so I would suggest putting the code directly into any high performance code (eg caching tags, like cfaccelerate and memcached) but for general use it is more convenient in the custom tag.