#40261 [Opn->Fbk]: Extremely slow data handling in specific situation

From: Date: Sun, 28 Jan 2007 01:15:25 +0000
Subject: #40261 [Opn->Fbk]: Extremely slow data handling in specific situation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-108138@lists.php.net to get a copy of this message
ID: 40261 Updated by: tony2001@php.net Reported By: thuejk at gmail dot com -Status: Open +Status: Feedback Bug Type: Performance problem Operating System: Linux PHP Version: 5.2.0 New Comment: Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. Previous Comments: ------------------------------------------------------------------------ [2007-01-28 00:30:02] thuejk at gmail dot com 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 this bug report at http://bugs.php.net/?id=40261&edit=1

« previous php.bugs (#108138) next »