Skip navigation.
 
mlRe: NSTextView and layout manager speed (was: how to be efficient)
FROM : glenn andreas
DATE : Thu Apr 28 18:03:40 2005

On Apr 28, 2005, at 10:44 AM, Keith Blount wrote:

> Thanks again for your reply. I ran Sampler, and all
> it's really telling me is that the NSLayoutManager
> calls are slowing things down (lots of private
> NSLayoutManager and typesetter methods to do with
> laying out the text). I've pasted my methods that call
> the layout manager methods during load below, in case
> anybody can suggest a way of doing it faster. The
> slowdown happens when there are a lot of notes that
> need loading in the margin of a document - for
> instance, with a document that has 200 notes, these
> methods have to be called 200 times when the document
> loads. On my G4 1Ghz, it takes 3 seconds to load a
> document with 200 notes, so maybe that isn't so slow,
> but if there is a way of getting them faster, I would
> love to find it.
>


Not sure how well this will fit your model, but it almost looks like
what is happening is that the layout for the first N glyphs is done
(because you need to get the location of N), and then you come back and
ask for N+M, so it needs to layout from N to M, etc... and it appears
that this start/stop layout has at least some overhead.

So the easy experiment is to get the layout of the last glyph needed,
which will cause all things before then to be laid out (and hopefully
be faster to get them).

You could also try using a delegate of the  the layout manager and
implement "layoutManager:didCompleteLayoutForTextContainer:atEnd:" and
spawn this whole thing off in a separate thread so that it will load
it, and then update your UI  on the main thread with your recalculated
locations.

Just some random ideas, for whatever it's worth.

(You might also want to save the last known locations in the file, so
you've got something to start with when you read in the document, and
adjust it as the "real" values are calculated).


Glenn Andreas                      <email_removed> 
  <http://www.gandreas.com/> oh my!
quadrium | build, mutate, evolve | images, textures, backgrounds, art

Related mailsAuthorDate
mlRe: NSTextView and layout manager speed (was: how to be efficient) Keith Blount Apr 28, 17:44
mlRe: NSTextView and layout manager speed (was: how to be efficient) glenn andreas Apr 28, 18:03