I am seeing some performance issues with Core Text when it is run on the original iPad.
I have created an editable view using Core Text and the UITextInput
protocol which is based around OmniGroup's OUIEditableFrame
.
When there is a fair amount of text in the view say 180 lines, typing/input lags greatly behind and one tap on a key usually takes 1-2 seconds.
Using instruments with the simulator I was able to narrow down the problem and find out what was taking so much time. Turns out it's because I redraw the frame with every key stroke, what takes up so much time is calling CTFramesetterCreateWithAttributedString
and CTFramesetterCreateFrame
.
I have to redraw with every key stroke so that the text gets updated, this means calling CTFramesetterCreateWithAttributedString
and CTFramesetterCreateFrame
.
Has anyone else come upon this problem, and if so, how did they get around it?
EDIT:
Did some further investigating and turns out that if the attributed string has no attributes then everything draws so much faster and without any lag. Changing the font, color or paragraphs style all slow it down. Any idea if this could have something to do with it?
Since my original question, I did some more investigating and found out that the more attributes the drawn string has, the longer it takes.
With that knowledge I decided to simply delete/hide any attributes (specifically kCTForegroundColor
) the user could not see, this sped up the drawing ten fold and made it a much more usable experience.