User guide

5.
Double-click on [self invalidateGraphic:graphic]; and you'll get Figure 6-20. This contains one
line of expensive code that tests for nested objects.
Figure 6-20
Source View: SKTGraphicView invalidateGraphic
It is interesting to note that even with this fairly quick analysis we have already identified several glaring
problems. The first problem we found was O(N
2
) behavior introduced by our code implementation hiding
within functions and the use of abstraction. In general it is good to create and use abstraction in your coding.
However, doing so can unintentionally introduce unnecessary performance pitfalls. Each of these functions is
well conceived locally, but when they are used together they combine to have poor scalability. Second, we
used expensive framework calls (in this case, to the undo manager) inside of a loop. Since undoing each step
of a “select all” operation really isn’t necessary, the expensive call can be moved up to a higher level, in order
to just undo all of the selects at once. This is an example of hoisting functionality to a higher level in the
execution tree. Finally, the invalidateGraphic routine was doing some heavyweight testing, and it would
clearly be worthwhile to see if we can move this testing outside of the inner loops, if possible.
Advanced Session Management and Data Mining
Example: Using Data Mining with a Time Profile
Retired Document | 2012-07-23 | Copyright © 2012 Apple Inc. All Rights Reserved.
167