Skip to content
This repository

DTCoreTextFontDescriptor Performance #19

Closed
myell0w opened this Issue April 05, 2011 · 19 comments

4 participants

Matthias Tretter Oliver Drobnik Stuart Carnie Nicolas Grilly
Matthias Tretter
  • (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.

Oliver Drobnik
Owner

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

Oliver Drobnik Cocoanetics closed this April 05, 2011
Matthias Tretter
  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

Oliver Drobnik
Owner
Matthias Tretter
Oliver Drobnik
Owner

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.

Stuart Carnie

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.

Oliver Drobnik
Owner
Stuart Carnie

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?

Oliver Drobnik
Owner
Stuart Carnie

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 :)

Stuart Carnie

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

Oliver Drobnik
Owner
Stuart Carnie

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.

Oliver Drobnik
Owner
Stuart Carnie

Indeed, the bug number is rdar://9350255

Stuart Carnie
Oliver Drobnik
Owner
Nicolas Grilly

@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.