[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: Review Request 111398: Fix O(N^2) complexity issue in KItemListView::slotItemsRemoved
From:       "Mark Gaiser" <markg85 () gmail ! com>
Date:       2013-07-05 9:43:43
Message-ID: 20130705094343.26116.9490 () vidsolbach ! de
[Download RAW message or body]

> On July 5, 2013, 7:10 a.m., Mark Gaiser wrote:
> > dolphin/src/kitemviews/kitemlistview.cpp, line 1095
> > <http://git.reviewboard.kde.org/r/111398/diff/1/?file=168518#file168518line1095>
> > 
> > This if doesn't seem to do anything, only the elseif.. Perhaps just remove it and \
> > end up with: 
> > if (i > lastRemovedIndex) {
> > itemsToMove.append(i);
> > continue;
> > }
> 
> Frank Reininghaus wrote:
> This 'if' check prevents that items which are *before* the removed range are \
> removed from the view.

No issue then. Although that's only the case if the order of i (thus the order of \
m_visibleItems) can be "random". You probably know best if it is or isn't :)


- Mark


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://git.reviewboard.kde.org/r/111398/#review35613
-----------------------------------------------------------


On July 4, 2013, 10:10 p.m., Frank Reininghaus wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://git.reviewboard.kde.org/r/111398/
> -----------------------------------------------------------
> 
> (Updated July 4, 2013, 10:10 p.m.)
> 
> 
> Review request for Dolphin.
> 
> 
> Description
> -------
> 
> In a directory which is shown in Dolphin, try the following (where N is a large \
> number > 100000): 
> touch {1..N}.png
> touch {1..N}.jpg
> 
> (wait until all files are shown in the view)
> 
> rm *.jpg
> 
> This will freeze Dolphin for quite some time (if not, try to increase the number of \
> files). This is because KItemListView::slotItemsRemoved() has a loop over all \
> removed item ranges (100000 in this case), and in each loop, it has another loop \
> that iterates through all items and tries to find visible ones. This is bad because \
> there is always only a small number of visible items, so we better just iterate \
> over those (similar to the approach in KItemListView::slotItemsInserted). 
> 
> Diffs
> -----
> 
> dolphin/src/kitemviews/kitemlistview.cpp 2ea6657 
> 
> Diff: http://git.reviewboard.kde.org/r/111398/diff/
> 
> 
> Testing
> -------
> 
> Dolphin takes a lot less time to remove many item ranges.
> 
> 
> Thanks,
> 
> Frank Reininghaus
> 
> 


[Attachment #3 (text/html)]

<html>
 <body>
  <div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
   <table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 \
solid;">  <tr>
     <td>
      This is an automatically generated e-mail. To reply, visit:
      <a href="http://git.reviewboard.kde.org/r/111398/">http://git.reviewboard.kde.org/r/111398/</a>
  </td>
    </tr>
   </table>
   <br />










<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <p style="margin-top: 0;">On July 5th, 2013, 7:10 a.m. UTC, <b>Mark \
Gaiser</b> wrote:</p>  <blockquote style="margin-left: 1em; border-left: 2px solid \
#d0d0d0; padding-left: 10px;">  



<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; \
border-collapse: collapse; margin: 2px padding: 2px;">  <thead>
  <tr>
   <th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; \
font-size: 9pt; padding: 4px 8px; text-align: left;">  <a \
href="http://git.reviewboard.kde.org/r/111398/diff/1/?file=168518#file168518line1095" \
style="color: black; font-weight: bold; text-decoration: \
underline;">dolphin/src/kitemviews/kitemlistview.cpp</a>  <span style="font-weight: \
normal;">

     (Diff revision 1)

    </span>
   </th>
  </tr>
 </thead>

 <tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
  <tr>

   <td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">void \
KItemListView::slotItemsRemoved(const KItemRangeList&amp; itemRanges)</pre></td>

  </tr>
 </tbody>



 
 

 <tbody>

  <tr>
    <th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">1090</font></th>  <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; ">            <span \
class="k">if</span> <span class="p">(</span><span class="o"><span \
class="hl">!</span></span><span class="n"><span class="hl">widget</span></span><span \
class="p">)</span> <span class="p">{</span></pre></td>  <th bgcolor="#e9eaa8" \
style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">1088</font></th>  <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; ">            <span \
class="k">if</span> <span class="p">(</span><span class="n"><span \
class="hl">i</span></span><span class="hl"> </span><span class="o"><span \
class="hl">&lt;</span></span><span class="hl"> </span><span class="n"><span \
class="hl">firstRemovedIndex</span></span><span class="p">)</span> <span \
class="p">{</span></pre></td>  </tr>

 </tbody>

</table>

  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This if doesn&#39;t seem \
to do anything, only the elseif.. Perhaps just remove it and end up with:

if (i &gt; lastRemovedIndex) {
    itemsToMove.append(i);
    continue;
}</pre>
 </blockquote>



 <p>On July 5th, 2013, 9:15 a.m. UTC, <b>Frank Reininghaus</b> wrote:</p>
 <blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: \
10px;">  <pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This &#39;if&#39; check \
prevents that items which are *before* the removed range are removed from the \
view.</pre>  </blockquote>







</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">No issue \
then. Although that&#39;s only the case if the order of i (thus the order of \
m_visibleItems) can be &quot;random&quot;. You probably know best if it is or \
isn&#39;t :)</pre> <br />




<p>- Mark</p>


<br />
<p>On July 4th, 2013, 10:10 p.m. UTC, Frank Reininghaus wrote:</p>








<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('http://git.reviewboard.kde.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;">  <tr>
  <td>

<div>Review request for Dolphin.</div>
<div>By Frank Reininghaus.</div>


<p style="color: grey;"><i>Updated July 4, 2013, 10:10 p.m.</i></p>






<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
 <table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" \
style="border: 1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">In a directory which is shown in Dolphin, try the following (where N is \
a large number &gt; 100000):

touch {1..N}.png
touch {1..N}.jpg

(wait until all files are shown in the view)

rm *.jpg

This will freeze Dolphin for quite some time (if not, try to increase the number of \
files). This is because KItemListView::slotItemsRemoved() has a loop over all removed \
item ranges (100000 in this case), and in each loop, it has another loop that \
iterates through all items and tries to find visible ones. This is bad because there \
is always only a small number of visible items, so we better just iterate over those \
(similar to the approach in KItemListView::slotItemsInserted).</pre>  </td>
 </tr>
</table>


<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: \
1px solid #b8b5a0">  <tr>
  <td>
   <pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: \
-moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">Dolphin takes a lot less time to remove many item ranges.</pre>  </td>
 </tr>
</table>




<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">

 <li>dolphin/src/kitemviews/kitemlistview.cpp <span style="color: \
grey">(2ea6657)</span></li>

</ul>

<p><a href="http://git.reviewboard.kde.org/r/111398/diff/" style="margin-left: \
3em;">View Diff</a></p>







  </td>
 </tr>
</table>








  </div>
 </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic