Optimizing


Finding Performance Problems



Many performance problems can be directly traced to naive use of particular classes or of the retain counting facilities in Foundation itself. By looking at the class list in the document window, you can see how many instance of each class have been allocated (Total), how many are still around (Current), what the maximum number of instances was at any point (Peak), how many were autorelease and what the percentage of the retain/release events were internal versus external (see the example code for more on internal vs. external retain counts).

Each of these statistics has various performance implications.

Fixing Performance Problems

Once you have located a dubious used of allocation resources, you can use the 'Stack Tree' panel to locate the cause of the problem.


Selecting an event type and a mark will allow you to view a hierarchical display of the stack frames leading to that type of event. For example, here we are looking at all of the stack paths leading up to the allocation of NSButton instances. Each node displays the number of events for which that node and all of its parents are responsible.

This panel can reveal unexpected behaviours in the classes you are using. For example, we discovered that OmniWeb3 was allocating large numbers of NSInvertedCharacter sets (many tens of thousands) during startup. By using this panel we were able to determine that most of them were due to using the natural language date parsing when reading the user's bookmarks file. By modifying our code to avoid this functionality in NSDate, we were able to trivially speed up Bookmark loading by a huge amount.