Skip to content

DTCoreTextFontDescriptor Performance #19

Closed
myell0w opened this Issue Apr 5, 2011 · 19 comments

4 participants

@myell0w
myell0w commented Apr 5, 2011
  • (CTFontRef)newMatchingFont :

// fast font creation
matchingFont = CTFontCreateWithFontDescriptor(fontDesc, pointSize, NULL);

This line takes forever, just did a quick Performance-Test with Instruments and this line took ~ 4.5 seconds on my iPhone 4.

@odrobnik
odrobnik commented Apr 5, 2011

No idea what you are talking about. I did extensive testing with instruments.

@odrobnik odrobnik closed this Apr 5, 2011
@myell0w
myell0w commented Apr 5, 2011
  DTAttributedTextView *textView = [[[DTAttributedTextView alloc] initWithFrame:CGRectMake(10, 25, contentView.frameWidth - 20, 200)] autorelease];
  NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];
  // Create attributed string from HTML
   NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         @"Helvetica", DTDefaultFontFamily,
                         @"gray",DTDefaultTextColor,
                         @"gray", DTDefaultLinkColor, nil];

NSAttributedString *string = [[[NSAttributedString alloc] initWithHTML:data options:options documentAttributes:NULL] autorelease];

Where html is a really short html-string.
Results in:

https://skitch.com/m.yellow/r21h9/instruments
https://skitch.com/m.yellow/r21h5/instruments

@odrobnik
@myell0w
@odrobnik
odrobnik commented Apr 5, 2011

Cannot duplicate your result. I copied this HTML into the CurrentTest.html. I copied your options to DemoTextViewController.m. No performance issue. newMatchingFont takes only liek 16.ms, viewDidAppear 40 ms for this file.

@stuartcarnie

I too am trying to figure this out, as it is taking several seconds in my app too. I'll post more when I find what the cause is.

@odrobnik
@stuartcarnie

No, Helvetica. Here is a reproducible sample:

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setObject:@"Helvetica" forKey:(id)kCTFontFamilyNameAttribute];
[attributes setObject:[NSNumber numberWithFloat:36.0f] forKey:(id)kCTFontSizeAttribute];
CTFontDescriptorRef fontDesc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);
CTFontRef matchingFont = CTFontCreateWithFontDescriptor(fontDesc, 36.0f, NULL);
CFRelease(matchingFont);
CFRelease(fontDesc);

I don't think it is your issue - it is definitely something to do with iOS. Perhaps introduced in 4.3?

@odrobnik
@stuartcarnie

On device is where the problem lies - in simulator it is fine. I have and iPad 2 (6-700ms) and iPad (1200ms) both on 4.3. I don't think I have any devices left below that :)

@stuartcarnie

I have also raised the issue on the Apple dev forums and created a bug report.

@odrobnik
@stuartcarnie

Seems strange that it would take that long to load a dynamic lib, but either way I created this gist to use GDC to preload.

@odrobnik
@stuartcarnie

Indeed, the bug number is rdar://9350255

@stuartcarnie
@odrobnik
@ngrilly
ngrilly commented Dec 20, 2012

@scarnie Just curious about this: "When I profiled into core text, it is a lot time spent in freetype library". Does it mean that Core Text uses FreeType or is it your extension that uses it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.