WKWebView freezes main thread when restoring app from background and can lead to app killing by the system.

Number:rdar://20068553 Date Originated:2015-03-06
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 8.1.3 [12B466], 8.3 beta 2 [12F5037c]
Classification:Serious bug Reproducible:Always
In the apps that use many WKWebView instances there is a problem with restoration from background which leads to UI freezing or even killing by system (because of not resuming in certain time interval). The problem affects Safari on iOS 8, as well.

If most of web view instances are not in view hierarchy when entering background and restoring back - restoration is always slow, even if you push "Home" and return back to your app without switching to another tasks.
If you switch to another apps, especially memory-demanding or using WKWebViews such as Safari and then return back to you app (make sure it was not unloaded by the system) - you get main thread completely freezed by communicating with WKWebView system process. This problem has a huge user experience impact and also can lead to a crash due to not resuming in time.

Steps to Reproduce:
Use the attached sample project

Case 1.
1. Load 5-10 WKWebView instances using "Create" button.
2. Press "Home", wait several seconds
3. Return to the app and see a restoration time - should be 1-4 seconds with the linear dependence on the web view instances count.

Case 2.
1. Same as before
2. Tap the "Workaround" button. This puts all WKWebView instances into view hierarchy.
2. Press "Home", wait several seconds
3. Return to the app and see a restoration time - should less than a second.
4. Switch to another apps, browse sites in Safari, etc.
5. Switch to the sample app again - restoration time should be several seconds again.

Expected Results:
Main thread is not blocked or blocked only for the active WKWebView instance

Actual Results:
Inter-process communication freezing main thread is performed for all WKWebView instances, so the restoration time is completely unacceptable (if keeping in mind a UI responsiveness principle).

iOS 8.1.3 [12B466], 8.3 beta 2 [12F5037c]


iPhone 5s, iPhone 6, iPad mini

'WKWebViewRestorationFromBackground.zip': https://yadi.sk/d/Pi04ndh9f5TWh


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!