Re: Fastest way to push strings to the screen in an NSView?
Re: Fastest way to push strings to the screen in an NSView?
- Subject: Re: Fastest way to push strings to the screen in an NSView?
- From: Scott Ellsworth <email@hidden>
- Date: Fri, 19 Nov 2004 15:15:26 -0800
On Nov 19, 2004, at 1:44 PM, Douglas Davidson wrote:
On Nov 18, 2004, at 11:33 PM, Scott Ellsworth wrote:
As an experiment, I ran the code with both the old drawInRect and the
new NSLayoutManager based code. If the new code is faster than the
old, then it should take up a smaller fraction of the total run time
than the old. Shark tells me pretty reliably that more time is spent
in the new is - 35.8% of runtime as compared with 12.9% for the code
it replaced. This seems counteintuitive.
(Three routines drawing text to the screen take up just over half the
time, according to shark, and this one was the easiest to refit and
test.)
The view is flipped, so the NSLayoutManager code should do pretty
well.
I have pasted the complete text of the two methods below, on the
chance that it is something about how I am using the layout manager.
This code draws a few hundred four digit numbers like 0101 or 3240 in
the view. Only visible numbers are drawn.
The problem here is that you aren't drawing the same string
repeatedly, you're drawing different strings every time. Remember, I
said that NSLayoutManager caches the information about the glyphs and
layout for the text, until the text changes. Well, if the text
changes every time you draw, that doesn't help much. It looks like
the string drawing routines are probably better for this particular
case.
Makes sense to me.
Thanks much (to you, Guy, Shawn, Robbie, John, Uli, and Ricky) for all
the advice.
I have some shark traces now, on both Panther and Tiger, and it looks
like I am spending the vast majority of my time in
drawGlyphsForGlyphRange/drawInRect. On the "drawStringInRect variants,
I am spending roughly half my time in CGContextShowGlyphs, called from
NSStringDrawingTextStroage _fastDrawGlyphs. The version using an
NSLayoutManager spends most of its time in NSLayoutManager
_drawGlyphsForGlyphRange.
Tiger tests show this staying about the same on my PowerBook/17/1.5Ghz,
likely because of the Radeon 8700 mobile. Thus, optimizing on Panther
is probably worth the time - Tiger is not going to make the work
needless.
I need to do a bit of data reduction - I suspect that I am only drawing
a very small number of actual unique strings. The hex numbers are
composed of a number between 01 and 32 next to one between 01 and 40,
while various other bits of data are either single hex digits, three
hex digits, or six hex digits in a sequence, but the distribution is
not random. I suspect far fewer than 10,000 objects could cache 95% of
what goes on the screen.
Thanks again,
Scott
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden