<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>idea Bug: _clearIIf in init.js has O(n^2) performance(JavaScript API)  in Developers Ideas</title>
    <link>https://community.esri.com/t5/developers-ideas/bug-cleariif-in-init-js-has-o-n-2-performance/idi-p/950312</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have included the functions from the&amp;nbsp;arcgis_js_v318_api.zip download below. (this functionality is mostly unchanged from 3.13, with only the '&lt;SPAN&gt;if(b)' bypass&amp;nbsp;being added in 3.18)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As you can see, the&amp;nbsp;_clearIIf function loops over the elements from the last graphic to&amp;nbsp;the first, then the remove function loops over the graphics elements from the first to the last to find it, always looking at every single graphic&amp;nbsp;element before finding the one to remove. &amp;nbsp;(_removeFeatureIIf is included as it links the two other functions)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If 80,000 graphics items are present, then the browser will pause for ~4 minutes, but at 10,000 graphic&amp;nbsp;items, it only takes about 4.5 seconds on the same machine. &amp;nbsp;And as this all takes place before any server calls, it can&amp;nbsp;not be a networking issue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In testing, reversing the loop in the remove function improved performance by a factor of 3, but it was still O(n^2) to clear the map. (it looks like the delete function may also have a forward loop)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In 3.18 it looks like a by-pass may have been added for cases where no elements are selected on the map,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From \arcgis_js_v318_api\arcgis_js_api\library\3.18\3.18\init.js:&lt;BR /&gt;_clearIIf:function(){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var a;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; a=this.featureLayer;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var e=a.graphics,c=a._selectedFeatures,b=a.getSelectedFeatures().length,d=a.objectIdField;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if(b)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(a=e.length-1;0&amp;lt;=a;a--){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var b=e&lt;A&gt;,g=b.attributes&lt;D&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g in c?b._count=1:(b._count=0,this._removeFeatureIIf(g))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; } &lt;BR /&gt;&amp;nbsp; &amp;nbsp; else a.clear(),this._featureMap={}&lt;/D&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_removeFeatureIIf:function(a){&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var e=this._featureMap&lt;A&gt;,c=this.featureLayer;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if(e){&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(e._count)return;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; delete this._featureMap&lt;A&gt;;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c._remove(e)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; return e&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From: \arcgis_js_v318_api\arcgis_js_api\library\3.18\3.18\dojox\gfx\svg.js&lt;BR /&gt;remove:function(a,c){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for(var b=0;b&amp;lt;this.children.length;++b)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.children&lt;B&gt;==a){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c||(a.parent=null,a.parentMatrix=null);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.children.splice(b,1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return this&lt;BR /&gt;}&lt;/B&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Dec 2016 19:22:12 GMT</pubDate>
    <dc:creator>TravisWatkins1</dc:creator>
    <dc:date>2016-12-02T19:22:12Z</dc:date>
    <item>
      <title>Bug: _clearIIf in init.js has O(n^2) performance(JavaScript API)</title>
      <link>https://community.esri.com/t5/developers-ideas/bug-cleariif-in-init-js-has-o-n-2-performance/idi-p/950312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have included the functions from the&amp;nbsp;arcgis_js_v318_api.zip download below. (this functionality is mostly unchanged from 3.13, with only the '&lt;SPAN&gt;if(b)' bypass&amp;nbsp;being added in 3.18)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As you can see, the&amp;nbsp;_clearIIf function loops over the elements from the last graphic to&amp;nbsp;the first, then the remove function loops over the graphics elements from the first to the last to find it, always looking at every single graphic&amp;nbsp;element before finding the one to remove. &amp;nbsp;(_removeFeatureIIf is included as it links the two other functions)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If 80,000 graphics items are present, then the browser will pause for ~4 minutes, but at 10,000 graphic&amp;nbsp;items, it only takes about 4.5 seconds on the same machine. &amp;nbsp;And as this all takes place before any server calls, it can&amp;nbsp;not be a networking issue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In testing, reversing the loop in the remove function improved performance by a factor of 3, but it was still O(n^2) to clear the map. (it looks like the delete function may also have a forward loop)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In 3.18 it looks like a by-pass may have been added for cases where no elements are selected on the map,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From \arcgis_js_v318_api\arcgis_js_api\library\3.18\3.18\init.js:&lt;BR /&gt;_clearIIf:function(){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var a;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; a=this.featureLayer;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; var e=a.graphics,c=a._selectedFeatures,b=a.getSelectedFeatures().length,d=a.objectIdField;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if(b)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(a=e.length-1;0&amp;lt;=a;a--){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var b=e&lt;A&gt;,g=b.attributes&lt;D&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; g in c?b._count=1:(b._count=0,this._removeFeatureIIf(g))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; } &lt;BR /&gt;&amp;nbsp; &amp;nbsp; else a.clear(),this._featureMap={}&lt;/D&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_removeFeatureIIf:function(a){&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; var e=this._featureMap&lt;A&gt;,c=this.featureLayer;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if(e){&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(e._count)return;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; delete this._featureMap&lt;A&gt;;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c._remove(e)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; return e&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From: \arcgis_js_v318_api\arcgis_js_api\library\3.18\3.18\dojox\gfx\svg.js&lt;BR /&gt;remove:function(a,c){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for(var b=0;b&amp;lt;this.children.length;++b)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.children&lt;B&gt;==a){&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c||(a.parent=null,a.parentMatrix=null);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.children.splice(b,1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return this&lt;BR /&gt;}&lt;/B&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2016 19:22:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-ideas/bug-cleariif-in-init-js-has-o-n-2-performance/idi-p/950312</guid>
      <dc:creator>TravisWatkins1</dc:creator>
      <dc:date>2016-12-02T19:22:12Z</dc:date>
    </item>
  </channel>
</rss>

