Code Monkey home page Code Monkey logo

Comments (10)

odrobnik avatar odrobnik commented on June 11, 2024

I have done much optimizing and there are many more things that could be done. For example incremental parsing or 2-step parting (1-structure, 2-format) or switch to libxml.

But long docs are low priority for now.

Sent from my iPhone

On 26.05.2011, at 09:07, shinss61 [email protected] wrote:

Thank you for your work!!!

I test lots of HTML files,
when parsing long html file, loading time is too long.... even more on my iPhone4, I can't load War and Peace sample file ;;;;

I'm a novice on objective-c, so that what's the problem..but what about using fast parser ???

Reply to this email directly or view it on GitHub:
https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/issues/27

from dtcoretext.

BlackBears avatar BlackBears commented on June 11, 2024

There is a related issue that occurs irrespective of the document length - I notice a long latency the first time it is used, but subsequent uses in the app are much faster. I wonder if there is some sort of "priming" that could be done at app startup. I haven't examined with Instruments yet; but it might be a solution to the latency issue.

from dtcoretext.

odrobnik avatar odrobnik commented on June 11, 2024

It's a known issue in iOS 4.x, supposedly fixed in iOS 5: http://www.cocoanetics.com/2011/04/coretext-loading-performance/

On Jun 9, 2011, at 6:28 AM, cocoa-factory wrote:

There is a related issue that occurs irrespective of the document length - I notice a long latency the first time it is used, but subsequent uses in the app are much faster. I wonder if there is some sort of "priming" that could be done at app startup. I haven't examined with Instruments yet; but it might be a solution to the latency issue.

Reply to this email directly or view it on GitHub:
https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/issues/27#comment_1334152

from dtcoretext.

odrobnik avatar odrobnik commented on June 11, 2024

There is nothing at this point that we can do about performance for enormous HTML documents. This can never be done in a synchronous way like initWithHTML is designed to work (being designed to work similar to Apple's initWithHTML on Mac).

from dtcoretext.

siuying avatar siuying commented on June 11, 2024

I dont sure if this is related, i'm working on a HTML file with a embeded PNG using data-uri, its about 1M and it took about 1minute to setup in initWithHTML on simulator ... i wonder if there are anyway to speed it up or work around....

from dtcoretext.

dickverbunt avatar dickverbunt commented on June 11, 2024

I'm experiencing the same issue with iOS 6.1. The first time it's slow (even with small HTML).
The first time it loads it takes like 1.2 seconds the second time 0.02 so that's a big difference.

I was able to fix this with the code you mentioned earlier on: http://www.cocoanetics.com/2011/04/coretext-loading-performance/ but don't know if this is the right way to do this. I didn't test this on iOS 5.0 though.

from dtcoretext.

odrobnik avatar odrobnik commented on June 11, 2024

@dickverbunt yes, this is one proper way. CoreText takes a while to load the font table. Check instruments.

To speed it up I have an override table for faster font lookup, check if this is being used for your fonts.

from dtcoretext.

thephotographer avatar thephotographer commented on June 11, 2024

Hi,

I am experiencing very long load times. The first time a page is loaded it is very slow (3-5 seconds), but subsequent times its loaded, its faster (0.1-0.2 seconds). If I then load a different page that uses additional fonts, then there is a load time on the first time that page is loaded.

Example: in my app I have a tab bar with screens of html text, the first tab is a blank VC so that nothing is loaded when the app launches, so that I can load the other screens in the order I want. I basically copied the DemoTextViewController from the demo app and pasted that into my app, removing the unnecessary things such as the debug toolbar, and segmented controls at the top as well as the other views that went along with the different view options.
In the first tab I display the ListTest.html text from the demo.
In the 2nd tab I display the CustomFont.html text from the demo.

When I press on the list tab it takes 3.5 seconds to load. then I press on the custom font tab, and it takes 1 second to load.

When I press on the custom font tab first, it takes 4.5 seconds to load, then i press on the list tab and it takes about 0.1 seconds to load.

This is on an iPhone 4 running iOS 6
On an iPad mini, the times are about 1 second quicker.

So i then tried to take the code that is causing the delay, and throw it at the start of my app in the app delegate:

CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();

NSData *data = [@"

init

" dataUsingEncoding:NSUTF8StringEncoding];
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Helvetica", DTDefaultFontFamily, nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:NULL];

NSLog(@"init in %f seconds", CFAbsoluteTimeGetCurrent() - startTime);

Sure enough, it takes 3.5 seconds to load. So no matter what length of text (within reason), either one word, or a few pages of text, the load time is the same.

Now I opened the DTCoreText DemoApp and pasted the same code into the app delegate... 1.07 seconds to load.

Originally I didnt have the DTCoreTextFontOverrides.plist in my project, so I added it, but there was no difference to the load times, exactly the same. I am very confused as to why the exact same code in my project takes 3.5 seconds, yet in the DemoApp project, on the same device, it takes only 1 second.

Do you have any ideas to why my project takes so long, yet the demo project is much quicker?

From the demo project, I compiled static libraries, and added the static library and the headers to my project.

Also, I tried to add the code from: http://www.cocoanetics.com/2011/04/coretext-loading-performance/
I tried the background thread code, and it made no difference, and the code below, all three times the measured time taken is the same, about 0.08 seconds.

  • (void)testWithSize:(CGFloat)size family:(NSString *)family
    {
    NSLog(@"Start");
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setObject:family forKey:(id)kCTFontFamilyNameAttribute];
    [attributes setObject:[NSNumber numberWithFloat:size] forKey:(id)kCTFontSizeAttribute];
    CTFontDescriptorRef fontDesc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes);
    CTFontRef matchingFont = CTFontCreateWithFontDescriptor(fontDesc, size, NULL);
    CFRelease(matchingFont);
    CFRelease(fontDesc);
    NSLog(@"Finish");
    }
  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    [self testWithSize:10 family:@"Courier New"];
    [self testWithSize:20 family:@"Georgia"];
    [self testWithSize:30 family:@"Helvetica"];
    // ...
    }

from dtcoretext.

odrobnik avatar odrobnik commented on June 11, 2024

Please try the current develop branch.

from dtcoretext.

thephotographer avatar thephotographer commented on June 11, 2024

Oh Wow!! Thank you Oliver. Incredible... Yesterday I was finding two very repeatable results, 3.5 seconds and 1 second for the init example I provided above. Today, with the new development branch I am seeing varied results ranging from 0.17 to 0.45 seconds to run the same code. I simply downloaded the zip file of the development branch, opened that project, compiled the static libraries, used lipo to merge the iOS and Simulator libraries into libDTCoreText_no_DTFoundation.a, I then moved that library to my existing project i was using yesterday overwriting the file. build and run, woo hoo instant results!

Loading the Custom Fonts Html page from the demo app took me 1.8 seconds today instead of the 4.5 seconds yesterday.

Hopefully this information is useful to you. I am very grateful for your help, and when I get everything working I will be more than happy to donate to you.

Yesterday I also saw some other strange things, such as I placed libDTCoreText_no_DTFoundation.a into my project, plus the required DTFoundation files, and compiled my project into a static library like usual. in the projects that use my static library, some of the projects did that code in the 1 second, and others did it in 3.5 seconds, yet the projects were exactly the same, just duplicate projects with different bundle ids. I could not find any explanation at all. I have my project template in a zip file, I would unzip it, change the bundle ID and project name, and build and run. it would run that code in 1 second. I did that a second time, exact same process, just unzipped the project, changed the project name and bundle ID, build and run, and it would take 3.5 seconds. Was very bizarre and doing my head in.

Thank you for your help, it is much appreciated!

from dtcoretext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.