I have a Python script using ArcPy. This script iterates over a set of ObjectIDs from a feature class ("Blocks") and calls a function to perform some calculations:
import arcpy
import datetime
def get_block_metrics(block_objectid):
# retrieve the points that lie within the block
# points and blocks are in different Enterprise geodatabases
block = arcpy.management.SelectLayerByAttribute(BLOCKS_FEATURE_CLASS, "NEW_SELECTION", "OBJECTID = 0".format(block_objectid), None)
points_in_block = arcpy.management.SelectLayerByLocation(points_layer, "INTERSECT", block, None, "NEW_SELECTION", "NOT_INVERT")
# return if there are no points within the block
if int(arcpy.management.GetCount(points_in_block)[0]) == 0:
del points_in_block
return
block_metrics = {}
# calculate some statistics for the block from the points
# this includes creating a summary statistics table on points_in_block
# also opening a search cursor on points_in_block and retrieving values
return block_metrics
Initially, this method will be called approximately 10,000 times. After, the script will be run once per day during which a call to this function will be made on the order of 100 times.
The first time this function is called, the calls to arcpy.management.SelectLayerByAttribute() and arcpy.management.SelectLayerByLocation() take a total of less than 1 second to complete.
The 100th time this method is called, the calls to these tools take a combined time of more than 5 seconds.
The 200th time this method is called, the calls to these tools take a combined time of more than 12 seconds.
After this method returns some insert and update cursors are opened on tables in the same enterprise geodatabase as the Blocks feature class, but the performance of these is stable for each iteration.
Why does the time taken to make these calls increase as additional calls are made? How can this be avoided?