Ways Apple COULD optimize -setNeedsDisplay
Ways Apple COULD optimize -setNeedsDisplay
- Subject: Ways Apple COULD optimize -setNeedsDisplay
- From: "Erik M. Buck" <email@hidden>
- Date: Sun, 16 Dec 2001 22:03:36 -0600
Apple could optimize the implementation of Cocoa window content display and
backing store flushing in conjunction with -setNeedsDisplay:
and -setNeedsDisplayInRect:.
Rather than simply storing the union of all invalid rectangles pending the
next trip through the event loop, Apple could do one or more of the
following:
1) Use a micro-tile array to efficiently keep track of invalid rectangles
2) Only union intersecting rectangles. Keep non-intersecting rectangles in
a data structure for pending display. A small fixed number of rectangles
could be used and unioning could be the fall back when running out of space
in the invalid rectangles data structure. Micro-tile arrays would be better
though.
3) Store a flag when -setNeedsDisplay: is called and then iterate over all
views in a window calling -display exactly once per event loop cycle for
each marked view. As it is now, many large expensive views that do not need
display are being displayed anyway.
4) Simply re-implement -setNeedsDisplay: to call -display immediately. As
stupid and counter productive as that sounds, it will probably improve
performance of most applications. Just for fun, I did this in a category of
NSView. The results are so far inconclusive but promising.
5) Quit breaking things that used to work!
I would be happy to implement any or all of the suggestions and donate the
code to Apple so that they don't have to divert any engineering resources.