<?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>topic Re: Why is arcpy.append_management so slow? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31710#M2500</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I usually assume that 'field' testing would just refer to attributes and not the geometry, but in any even, it is even more confusing since it appears that the geometry just gets dumped in and not 'fixed' because you have to use Union to fix geometries that may overlap, intersect or whatever...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #4c4c4c; font-family: 'Avenir Next W01','Avenir Next W00','Avenir Next','Avenir','Helvetica Neue',sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;This tool will not planarize features when they are added to the target dataset. All features from both the input feature class and the target feature class will remain intact after the append, even if the features overlap. To combine, or planarize, feature geometries, use the &lt;/SPAN&gt;&lt;SPAN style="color: #4c4c4c; font-family: &amp;amp;quot; avenir next w01&amp;amp;quot;,&amp;amp;quot;avenir next w00&amp;amp;quot;,&amp;amp;quot;avenir next&amp;amp;quot;,&amp;amp;quot;avenir&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;A href="http://pro.arcgis.com/en/pro-app/tool-reference/analysis/union.htm" style="color: #0074b8; text-decoration: none;"&gt;Union&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #4c4c4c; font-family: 'Avenir Next W01','Avenir Next W00','Avenir Next','Avenir','Helvetica Neue',sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; tool.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Jan 2019 23:14:13 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2019-01-24T23:14:13Z</dc:date>
    <item>
      <title>Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31707#M2497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I was working on a little project merging a large number of datasets into one. Irritatingly, each partial dataset was residing in a feature class of the same name, scattered across several hundred file geodatabases, also of the same name but with an added publication date in the filename, and each stuffed into a ZIP archive.&lt;/P&gt;&lt;P&gt;My process:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Iterate over a list of archives&lt;/LI&gt;&lt;LI&gt;Unzip&amp;nbsp;each GDB's, while logging the occasional bad ZIP file&lt;/LI&gt;&lt;LI&gt;With all GDB in the same directory, iterate over GDB's&lt;/LI&gt;&lt;LI&gt;Access the feature class&lt;/LI&gt;&lt;LI&gt;Copy all features into a in-memory "temp" feature class&lt;/LI&gt;&lt;LI&gt;Add a date field and populate it with the the publication date of GDB.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So much for background. --- But which arcpy method to use for writing all these partial datasets to an SDE feature class? All that was needed was to append all features from source to the target feature class with matching&amp;nbsp;list of fields (identical schema). So I tried:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.append_management(['in_memory\\temp'], target_fc, "TEST")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This seemed to work fine for a smaller test dataset. With approx. 1200 features per feature class, the process took about 6 sec fer feature class. That's slower than 1200 inserts in SQL but I could live with that. So I added a logger from the Python standard library logging module to get some info on processing time info and pointed my script at the directory with 800+ GDB's, an 80 GB directory with all the database overhead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And it ran... and ran... and ran...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The 1st run:&lt;/STRONG&gt;&lt;BR /&gt;Start 01/22/2019 04:14:14 PM&lt;BR /&gt;Finish 01/22/2019 11:41:36 PM&lt;BR /&gt;Total: 7h:27m:22s&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was not prepared for that kinda of lengthy ordeal and started researching.&amp;nbsp;I stumbled across this thread here (&lt;A href="https://community.esri.com/thread/206440" target="_blank"&gt;Loop processing gradually slow down with arcpy script&lt;/A&gt;) and the mention&amp;nbsp;arcpy.SetLogHistory caught my attention. I had no idea that arcpy logs to an ESRI history file even when you're running a code outside of any application.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I set the flag to False, and ran my script again.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;
arcpy.SetLogHistory(False)
&lt;/BLOCKQUOTE&gt;&lt;STRONG&gt;The 2nd run:&lt;/STRONG&gt;
01/23/2019 05:03:23 PM
01/24/2019 12:49:21 AM
Total: 7h:45m:58s&lt;/PRE&gt;&lt;P&gt;Even worse!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.CopyFeatures_management(fc_source,'in_memory\\temp')
arcpy.AddField_management('in_memory\\temp',"date_reported",'DATE')

#this is the date portion of the GDB name
datestring = gdb[-12:-4] 
updatedate = datetime.strptime(datestring, '%Y%m%d').strftime('%m/%d/%Y')

fields = "date_reported"

with arcpy.da.UpdateCursor('in_memory\\temp', fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;row[0] = updatedate
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cursor.updateRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.Append_management(['in_memory\\temp'], SDE_target_fc, "TEST")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;logger.info("Successfully wrote data for {0} to SDE".format(datestring))
&amp;nbsp;&amp;nbsp;&amp;nbsp;except:
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; logger.info("Unable to write data to SDE...")
 arcpy.Delete_management("in_memory\\temp")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This was driving me crazy, so I pulled the&amp;nbsp;timestamps from my log and plotted the diff's for each feature class&amp;nbsp;using matplotlib/pandas for both runs. X is a count of all the iterations&amp;nbsp;over feature classes, Y is the time in seconds each INSERT (or the portion of the code doing the append) took&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/435770_plot_times_arcappend.png" /&gt;&lt;/P&gt;&lt;P&gt;Two questions that come to mind:&lt;/P&gt;&lt;P&gt;1) Why does each INSERT take longer than the one before?&lt;/P&gt;&lt;P&gt;2) What the heck happens when I get to&amp;nbsp;feature class #500 or so where that steady slowing trend goes berserk?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just for sake of completeness, I&amp;nbsp;also ran the script using the following ("NO_TEST") - with the same result.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.Append_management(['in_memory\\temp'], SDE_target_fc, "NO_TEST")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since arcpy.append clearly wasn't performing, I followed the advice from this thread (&lt;A class="link-titled" href="https://gis.stackexchange.com/questions/90372/using-arcpy-da-insertcursor-to-insert-entire-row-that-is-fetched-from-search-cur" title="https://gis.stackexchange.com/questions/90372/using-arcpy-da-insertcursor-to-insert-entire-row-that-is-fetched-from-search-cur" rel="nofollow noopener noreferrer" target="_blank"&gt;Using arcpy.da.InsertCursor to insert entire row that is fetched from search cursor?)&lt;/A&gt;&amp;nbsp;and replaced arcpy.append with:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dsc = arcpy.Describe(target_fc)
fields = dsc.fields
fieldnames = [field.name for field in fields]
...
with arcpy.da.SearchCursor('in_memory\\temp',fieldnames) as sCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;with arcpy.da.InsertCursor(target_fc,fieldnames) as iCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for row in sCur:
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;iCur.insertRow(row)&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;Th 3rd run:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;01/24/2019 01:40:31 PM&lt;BR /&gt;01/24/2019 02:19:09 PM&lt;BR /&gt;Total: 38m:38s&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now we're talking. So much faster! In fact, 2318 seconds for 850 INSERTS, comes out to about 3 sec per transaction, and when you&amp;nbsp;plot it:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-2 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/435771_insert_cursor.png" /&gt;&lt;/P&gt;&lt;P&gt;Now, that's the kind of behavior I'd expect. That no matter how many INSERTS you do, they always take about 2-4 seconds. So my question: &lt;EM&gt;&lt;STRONG&gt;What&amp;nbsp;in the world is append_management doing? Clearly, it's the wrong tool for what I was doing despite its name, or is it not?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:56:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31707#M2497</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2021-12-12T15:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31708#M2498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;a good guess would be validating the geometry, since you used no test for attributes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jan 2019 22:22:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31708#M2498</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-01-24T22:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31709#M2499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But I tried both "TEST" and "NO_TEST". Both took about the same time, 7+ hours.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jan 2019 22:30:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31709#M2499</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2019-01-24T22:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31710#M2500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I usually assume that 'field' testing would just refer to attributes and not the geometry, but in any even, it is even more confusing since it appears that the geometry just gets dumped in and not 'fixed' because you have to use Union to fix geometries that may overlap, intersect or whatever...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #4c4c4c; font-family: 'Avenir Next W01','Avenir Next W00','Avenir Next','Avenir','Helvetica Neue',sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;This tool will not planarize features when they are added to the target dataset. All features from both the input feature class and the target feature class will remain intact after the append, even if the features overlap. To combine, or planarize, feature geometries, use the &lt;/SPAN&gt;&lt;SPAN style="color: #4c4c4c; font-family: &amp;amp;quot; avenir next w01&amp;amp;quot;,&amp;amp;quot;avenir next w00&amp;amp;quot;,&amp;amp;quot;avenir next&amp;amp;quot;,&amp;amp;quot;avenir&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;A href="http://pro.arcgis.com/en/pro-app/tool-reference/analysis/union.htm" style="color: #0074b8; text-decoration: none;"&gt;Union&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #4c4c4c; font-family: 'Avenir Next W01','Avenir Next W00','Avenir Next','Avenir','Helvetica Neue',sans-serif; font-size: 15.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; tool.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jan 2019 23:14:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31710#M2500</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-01-24T23:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31711#M2501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll definitely read up on that some more. When I first noticed that&amp;nbsp;flag, I wondered how that really applied to me since my source fc's are all the same schema for sure. No checking needed. But the documentation suggested otherwise. Either way, lesson learned likely is to use the InsertCursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jan 2019 23:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/31711#M2501</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2019-01-24T23:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why is arcpy.append_management so slow?</title>
      <link>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/1019809#M59629</link>
      <description>&lt;P&gt;Thanks a lot for sharing. Append is extremely slow. It was taking me more than 24 hours to run just one single. Let me test Insert Cursor.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:24:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-is-arcpy-append-management-so-slow/m-p/1019809#M59629</guid>
      <dc:creator>HerveHabonimana</dc:creator>
      <dc:date>2021-01-25T20:24:48Z</dc:date>
    </item>
  </channel>
</rss>

