Issues

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

Issue Type: Performance Improvement Created: 2010-09-22T14:04:32.000+0000 Last Updated: 2011-06-18T03:07:48.000+0000 Status: Resolved Fix version(s): - 1.11.3 (01/Feb/11)

Reporter: Mark Reidenbach (mreiden) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Amf

Related issues: - ZF-7493

Attachments: - Amf.Combined-NoObjectsByRef.diff

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

Posted by Mark Reidenbach (mreiden) on 2010-09-22T14:10:50.000+0000

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".

Posted by Ralph Schindler (ralph) on 2010-11-21T07:21:52.000+0000

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

Posted by Ogre The Great (ogrethegreat) on 2010-12-21T09:47:38.000+0000

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; }

Posted by Matthew Weier O'Phinney (matthew) on 2011-01-28T09:55:17.000+0000

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.

Posted by Ralph Schindler (ralph) on 2011-05-28T21:39:08.000+0000

Can someone test this?

Posted by Mark Reidenbach (mreiden) on 2011-06-03T15:08:17.000+0000

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?

Posted by Matthew Weier O'Phinney (matthew) on 2011-06-03T21:20:58.000+0000

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

Posted by Ryan Masten (doobywho) on 2011-06-16T02:42:57.000+0000

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

Posted by pt (jcrocks) on 2011-06-18T03:07:48.000+0000

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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts