Issues

ZF-10487: ZendAMF serialization slow? - Supplied patch not applied

Description

I've compared ZendAMF to AMFPHP, by returning a dataset with 5000+ rows from a table, using the exact same code (both in PHP, and AS3). ZendAMF averages a 16 second return time, whereas AMFPHP returns in 3 seconds. I'm guessing the added time is coming from the process of serializing data to send back to Flash.

Comments

I cloned bug ZF-7493 in hopes that having a bug that has not been "fixed" will get someone to notice that the correct patch has not been applied yet.

Please apply patch "Amf.perform.ref-writeString-1.10.5.patch".

Re-assigning to wade to have a look at suggested fix.

In addition to Mark's patch, the issue also effects Object serialization. Even with Mark's patch if one is encoding a large dataset of objects, the issue still appears. I've taken Mark's logic and used spl_object_hash() to get vastly improved performance for my needs. In essence, the performance drops exponentially as size of the array increases. Its even worse with the object array_search than it is with strings. I went ahead and put up the diff but this piece should probably be fixed to use SPL where available and otherwise require a UUID on any object passed to the serializer or some other logic along the lines. Point being is to build a hash to search on rather than exhaustive object comparison. Note this diff is based on the original. Mark made some other changes to pass the marker type which are not shown here.

@@ -386,7 +386,7 @@ $object = &$objectByVal; }

  • $ref = array_search($object, $this->_referenceObjects,true);
  • $ref = array_key_exists(spl_object_hash($object), $this->_referenceObjects) ? $this->_referenceObjects[spl_object_hash($object)] : false;

     // quickly handle object references 
     if ($ref !== false){ 
    

    @@ -394,7 +394,7 @@ $this->writeInteger($ref); return true; }

  • $this->_referenceObjects[] = $object;
  • $this->_referenceObjects[spl_object_hash($object)] = count($this->_referenceObjects); return false; }

I've applied both Mark's patch as well as the improvements suggested in the previous comment (with minor modifications -- I store the object hash locally so it doesn't need to be computed multiple times). The changes are in trunk in r23682. Please test, and, if the changes pose no issues AS WELL AS demonstrate better performance, please post a comment so I can merge to the 1.11 release branch.

Can someone test this?

I checked out revision 24104 and everything works for our project. It also looks like Amf.perform.ref-writeString-1.10.5.patch is included in ZF 1.11.7 so this bug could be closed?

Marking as resolved, as patch was merged in time for 1.11.3.

I am still having horrible performance. What took 200ms on AMFPHP takes 5s on ZendAMF 1.11.7 Thoughts?

X2 on this comment => "I am still having horrible performance. What took 200ms on AMFPHP takes 5s on ZendAMF 1.11.7"

Returning small simple arrays is fine but other than that, very slow. Returning ~200 objects with some properties containing objects takes about 5 seconds. It's not the function that creates the objects either. I capture the micro-time at the beginning of the function and immediately before the return and it's less than half a second. So it takes 4.5 seconds to return the objects to Flex.