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?
Core Text is a low-level text engine that when used alongside the Core Graphics/Quartz framework, gives you fine-grained control over layout and formatting. With iOS 7, Apple released a high-level library called Text Kit, which stores, lays out and displays text with various typesetting characteristics.
Core Text is a Core Foundation style API in Mac OS X, first introduced in Mac OS X 10.4 Tiger, made public in Mac OS X 10.5 Leopard, and introduced for the iPad with iPhone SDK 3.2.
You probably should not be using CTFramesetter
to create something like UITextView
. Instead, you should likely keep an array of CTLine
references. If you need help with word breaking, then you can use a CTTypeSetter
, but you only need to hand it lines at the current caret and below (you'll still be creating and destroying typesetters a bit, so watch how much you ask of them).
One nice thing about keeping an array of CTLines
is that you can throw away the ones you don't need if you're low on memory and reconstruct them later. Just keep track of the character range for each line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With