High latency in WKWebView script execution methods

Originator:mihai.parparita
Number:rdar://17956460 Date Originated:
Status:Open Resolved:
Product:iOS SDK Product Version:8.0
Classification:Performance Reproducible:Always
 
A full round JavaScript evaluation round trip in WKWebView, as measured by:

// start
[_wkWebView evaluateJavaScript:@"..." completionHandler:^(id result, NSError *error) {
   // end
}];

Seems to take ~5 ms on an iPhone 5c running iOS 8 beta 5. The equivalent UIWebView method (stringByEvaluatingJavaScriptFromString:) is about 10x faster (measured via the harness at https://github.com/mihaip/web-experiments/tree/master/uiwebview-communication).

Based on an Instruments profile (see https://www.dropbox.com/s/20vuhdv2siweymr/evaluateJavaScript.png), a large part of the time is spent in JSContext construction when parsing the return value. If caching of JSContexts is not feasible, then an alternate method where the return value is unparsed (or just always stringified) would be most welcome.

Relatedly, postMessage suffers from the same performance problem (see https://www.dropbox.com/s/d7djzqe3h075cs3/postMessage.png); it also spends a large amount of time in JSContext construction.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!