I recently finished developing a python toolbox tool that ends up calling the arcpy.AddField_management() function about 25 times or so. I first developed it as a standalone script to get it working before I connected it up to my python toolbox. When I started testing the tool with the exact same data I found that the run time went up from ~20 seconds in standalone to ~80 seconds when run from a python toolbox inside an ArcGIS Pro map, a 4x increase. After playing around some more I found that it was definitely the AddField tool slowing it down, and then I noticed that if I close the attribute table in the Pro map the run time goes down to ~50 seconds.
So what I think is happening is that that the Pro map is busy revalidating locks and updating the GUI, etc. unnecessarily mid-script. I also notice that when the add field tools are called the "Add" and "Calculate" field buttons start alternating being grayed out, like it is cycling through locks and UI updates or something.
These alternate being gray
Is there any way to prevent this from happening? Can I somehow pause all that validation or whatever it is for the duration of my script? If not, is there a more efficient method to add fields? These short runtimes may not seem like a big deal but I now realize that I have many tools that have a LOT of calls to AddField and this is likely something that happens throughout my toolbox. I would like to make sure my code is as clean and efficient as practical.
All of the feature classes that have the add field function called on are in_memory layers, and are copied to new feature classes for the output layers.