Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Preload a Core Text font descriptor if you are having performance issues in iOS 4.3
#import <CoreText/CoreText.h>
...
// preload
dispatch_queue_t queue = dispatch_queue_create("com.company.worker", NULL);
dispatch_async(queue, ^(void) {
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);
});
dispatch_release(queue);
@zimok

I, i'm figuring the same CoreText performance issues.
I found your workaround, but I don't understand how and where to preload CoreText framework.
Where should I put this snippet?

Thanks.

@stuartcarnie

This code will preload core text by running this little block of code on a separate thread. You can add this to your UIAppDelegate

@misterdjules

Is it necessary to spawn one separate thread per font/font-size used? For instance, I'm using Helvetica Neue Light and Helvetica Neue Ultra Light fonts, both with 16px font size, should I create one thread for both?

I tried with various combinations and it doesn't seem to really preload anything, there's still a delay when loading the first chunk of text. Loading times are much better after that. Any ideas?

@misterdjules

Actually, it seems it's correctly preloading these fonts, because the delay before first text render is much better when the preloading code is active than when it's not. However, there is still a small delay left on first text render. Did you experience this too?

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.