6.0.0-beta1
8/28/25

[#14075] Large mailboxes takes many seconds to load and causes CPU at 100%
Summary Large mailboxes takes many seconds to load and causes CPU at 100%
Queue Horde Framework Packages
Type Enhancement
State Resolved
Priority 1. Low
Owners slusarz (at) horde (dot) org
Requester cunha17 (at) gmail (dot) com
Created 08/03/2015 (3678 days ago)
Due
Updated 08/05/2015 (3676 days ago)
Assigned 08/05/2015 (3676 days ago)
Resolved 08/05/2015 (3676 days ago)
Milestone
Patch No

History
08/05/2015 07:16:25 AM Michael Slusarz Comment #4
Assigned to Michael Slusarz
State ⇒ Resolved
Reply to this comment
Your suggested improvement was broken for empty thread objects - 
array_replace requires at least one array.

Additionally, there's significant overhead involved with 
call_user_func_array() and array_replace().  Better just to use the 
array union operator - benchmarked at 25% faster on a 500,000 message 
thread object, with the same maximum memory usage.
08/05/2015 07:13:37 AM Git Commit Comment #3 Reply to this comment
Changes have been made in Git (master):

commit 7d4019642f279fc5471bd330e9654a976154a280
Author: Michael M Slusarz <slusarz@horde.org>
Date:   Wed Aug 5 01:12:01 2015 -0600

     [mms] Improved performance of Horde_Imap_Client_Data_Thread 
object when containing large number of messages (Request #14075).

  .../lib/Horde/Imap/Client/Data/Thread.php          |    7 +-
  framework/Imap_Client/package.xml                  |    8 ++-
  .../test/Horde/Imap/Client/Data/ThreadTest.php     |   66 
++++++++++++++++++++
  3 files changed, 75 insertions(+), 6 deletions(-)

http://github.com/horde/horde/commit/7d4019642f279fc5471bd330e9654a976154a280
08/05/2015 06:41:54 AM Michael Slusarz Comment #2
Type ⇒ Enhancement
Priority ⇒ 1. Low
State ⇒ Assigned
Reply to this comment
This is not a bug report, since behavior is correct.
08/05/2015 05:03:09 AM Michael Rubinsky Priority ⇒ 1. Low
 
08/03/2015 11:28:46 PM cunha17 (at) gmail (dot) com Comment #1
Priority ⇒ 3. High
State ⇒ Unconfirmed
Patch ⇒ Yes
Milestone ⇒
Queue ⇒ Horde Framework Packages
Summary ⇒ Large mailboxes takes many seconds to load and causes CPU at 100%
Type ⇒ Bug
Reply to this comment
The library in question is Horde_Imap_Client.

The class where the performance problem reside is 
Horde_Imap_Client_Data_Thread.

And the method causing the high CPU usage is _getAllIndices().

This method uses a simple iteration through _thead array (in my case 
having 8088 elements) and merges the keys of each sub-array with the 
previous one. So it calls array_merge and array_keys 8088 times:

protected function _getAllIndices()
     {
         $out = array();
         reset($this->_thread);
         while (list(,$v) = each($this->_thread)) {
             $out = array_merge($out, array_keys($v));
         }

         return $out;
     }

I replaced this iteration with this and the performance issue were gone:

protected function _getAllIndices()
     {
             return array_keys(call_user_func_array('array_replace', 
$this->_thread));
     }

Hope it helps and best regards,

Cristiano da Cunha Duarte

Saved Queries