From: Operating system: Linux PHP version: 5.3.3 Package: Performance problem Bug Type: Feature/Change Request Bug description:unserialize() performance
Description: ------------ Performance of built-in unserializer degrades at unexpectedly high rate with the increase of unserialized data size (rather, with number of serialized items). Say, unserializing a plain array of ~1000000 integers might take somewhat 10 secs on average P4 machine, and the worst part is that the time raises quadratically (O(n^2)) with the array size, i.e. ~2000000-ish array would take 40 secs or so. The main performance killer is var_hash linked list where every extracted variable is pushed. It is looked up sequentally from the very beginning up to, in fact, the very end during every push operation (var_push() in ext/standard/var_unserializer.c). It appears that looking from the end (or just storing last used element elsewhere) would save a lot of cycles. In my tests doing so reduced the unserialize time from 7 secs to ~0.3 sec on 1000000-size array and size dependency apparently changed to something more like O(n*log(n)) -- Edit bug report at http://bugs.php.net/bug.php?id=52832&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52832&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52832&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52832&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52832&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52832&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52832&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52832&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52832&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52832&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52832&r=support Expected behavior: http://bugs.php.net/fix.php?id=52832&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52832&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52832&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52832&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52832&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52832&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52832&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52832&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52832&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52832&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52832&r=mysqlcfg