We as developer know that sometimes things may take longer. The users don't know that. If they see the beachball they tend to do a force-quit of the application. Which may corrupt user data which lead to support emails.

There is a simple trick in Instruments so that you can quickly identify sections in your code that cause a beachball.

As usual I start Mail Archiver and start analysing with Instruments.

Then I cheat a bit and start an activity that I know that causes a beachball. In Instruments this shows up as a red bar: Instruments with beach ball

To make the analysis concentrate just on the activity that caused the beachball select an area by doing a drag-click over the red bar:

Instruments with area in red bar selected

Instead of showing the data for the complete run I now see only the data for the selected time. I can now drill-down to see the activity that caused the beachball. Here it's a database activity.

To reset the selection use View -> Clear Inspection Range in the menu:Reset selection in Instruments

I had several cases where an analysis like the one above showed me that a call to replace line endings or iterating over 100k files caused a beachball. As result the MBS plugin from Christian Schmitz now has several plugin methods which don't show the beachball.