Performance increase in Helper/Search.php on big resultset

Please report bugs here!

Moderator: Thorsten

Post Reply
dajoker
Posts: 59
Joined: Sat Jan 30, 2010 1:01 am

Performance increase in Helper/Search.php on big resultset

Post by dajoker » Thu Jul 25, 2013 5:19 am

It's been a while, but it's good to be back. While poking through some code I found the ./phpmyfaq/inc/Helpder/Search.php function which is doing some neat pagination stuff of course. An idea for a performance improvement, for which I have yet to find any downsides, is to NOT loop through the pages of FAQs after the current FAQ, since that is effectively what happens right now. A unified diff implementing this change follows:

<diff file="./phpmyfaq/inc/PMF/Helper/Search.php">
--- phpmyfaq/inc/PMF/Helper/Search.php-orig 2013-06-26 12:32:58.000000000 -0600
+++ phpmyfaq/inc/PMF/Helper/Search.php 2013-07-24 21:58:05.399000000 -0600
@@ -270,7 +270,8 @@

foreach ($resultSet->getResultset() as $result) {
if ($displayedCounter >= $confPerPage) {
- continue;
+ //echo 'hi';continue;
+ break;
}
$counter++;
if ($counter <= $firstPage) {
</diff>

Basically the commented line is there for me to see what I did, but this change just replaces the single 'continue;' with a 'break;' which drops out of the loop. This matters to me when I get a resultset that is close to 500 pages long (or more for some search results). While I have not tried timing the difference in performance, it's pretty simple to see that the loop is running unnecessarily and can be optimized, hopefully without any drawbacks.

-dajoker

Thorsten
Posts: 15091
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Performance increase in Helper/Search.php on big results

Post by Thorsten » Thu Jul 25, 2013 5:16 pm

Hi,

awesome, I added it to 2.8.2

Thanks!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist

Post Reply