Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Text Performance

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?

like image 828
Joshua Avatar asked May 19 '11 17:05

Joshua


People also ask

What is Core Text iOS swift?

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.

What is core text in English?

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.


1 Answers

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.

like image 76
Rob Napier Avatar answered Oct 06 '22 22:10

Rob Napier