UIWebViews Are Horrible

After spending the last few days trying to improve performance with a local html document I am convinced that UIWebView is a horrible component that should be limited to only showing remote web page documents.  What brought upon this rant, and proposed solution for it, had to do with the half a second flicker between clicking on a TabBarItem in a TabBarController and the rendering of the local html file itself. If a user navigates away from the TabBarItem and then back again it will load instantly since the contents are now cached in memory.  However, I just couldn’t get past that initial flicker.

There are three different methods of loading an html document into.
  1. - (void)loadRequest:(NSURLRequest *)request
  2. - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
  3. - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
Source: http://cwil.es/uJznzA

The first thing I tried was timing each method to see which was faster.



The difference is negligible.  The second route that I attempted was to use Grand Central Dispatch (GCD).  Using GCD to manage process intensive logic that would normally block the main thread makes EVERYTHING so much better.  

Unfortunately, this is not the case with loading the local html file.  In fact, the speeds were essentially the same as using the single threaded paradigm.  I am assuming this to be the case because of the slight overhead of managing the threads. At the end of the day I am not gaining any performance.

Due to this frustration I am going to look into using @Cocoanetics NSAttributedString-Additions-for-HTML and save UIWebViews for remote display only.

Test Results (iOS5 Simulator. Ran code 4 separate times in - (void)viewDidLoad)

Main Thread Only

loadRequest
  1. 0.024776 seconds
  2. 0.025888 seconds
  3. 0.023575 seconds
  4. 0.026948 seconds
loadHTMLString
  1. 0.020844 seconds
  2. 0.063485 seconds
  3. 0.026386 seconds
  4. 0.057899 seconds
loadHTMLData
  1. 0.027755 seconds
  2. 0.036826 seconds
  3. 0.026125 seconds
  4. 0.025203 seconds
Grand Central Dispatch

loadRequest
  1. 0.029463 seconds
  2. 0.025321 seconds
  3. 0.026808 seconds
  4. 0.033857 seconds
loadHTMLString
  1. 0.025549 seconds
  2. 0.030053 seconds
  3. 0.027117 seconds
  4. 0.022959 seconds
loadHTMLData
  1. 0.035207 seconds
  2. 0.034666 seconds
  3. 0.029324 seconds
  4. 0.023069 seconds