#40261 [NEW]: Extremely slow data handling in specific situation

From: Date: Sun, 28 Jan 2007 00:30:02 +0000
Subject: #40261 [NEW]: Extremely slow data handling in specific situation
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-108136@lists.php.net to get a copy of this message
From:             thuejk at gmail dot com
Operating system: Linux
PHP version:      5.2.0
PHP Bug Type:     Performance problem
Bug description:  Extremely slow data handling in specific situation

Description:
------------
I have some code which produces unacceptible performance in a specific
situation. Making a completely trivial change improves performance a
hundred-fold or more.

The problem is 100% reproducible.

The code looks something like:

/* pseudocode*/
function get_data_from_pgsql(){
  ...
  $map = Array();
  foreach ($rows as $row) {
     $map = row[index];
  }
  return $map;
}
$data1 = get_data_from_pgsql
$data2 = get_data_from_pgsql

One run with 10000 rows of result took 8.77 seconds, which is clearly
silly. Making the extremely trivial change of moving the code block 
  foreach ($rows as $row) {
     $map = row[index];
  }
out of the function get_data_from_pgsql(), the code suddently only takes
0.1 seconds to run (factor 90)! Having more rows in the result makes the
factor difference larger; it seems to increase quadratically.

Not saving the return values in $data1 and $data2 also improves
performance immensely.

PHP 5.1.5 did not have this problem (or at least it was much smaller).

Reproduce code:
---------------
http://thuejk.dk/test.php.txt

You need a running postgresql database with one table, which has at least
10000 entries.

change the line
  $translate_outside_function = false;
at the top of the file to see the difference mentioned above.


-- 
Edit bug report at http://bugs.php.net/?id=40261&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40261&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40261&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40261&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40261&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=40261&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40261&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40261&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40261&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40261&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40261&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=40261&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=40261&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40261&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40261&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40261&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40261&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40261&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40261&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40261&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40261&r=mysqlcfg


Thread (18 messages)

« previous php.bugs (#108136) next »