[Webkit-unassigned] [Bug 184015] New: API::SharedJSContext caches its JSContext for at most one second

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Mar 26 11:07:08 PDT 2018


https://bugs.webkit.org/show_bug.cgi?id=184015

            Bug ID: 184015
           Summary: API::SharedJSContext caches its JSContext for at most
                    one second
           Product: WebKit
           Version: Safari 11
          Hardware: iPhone / iPad
                OS: iOS 11
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: WebKit API
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: ide at jameside.com

The -[WKWebView evaluateJavaScript:completionHandler:] API and any other APIs that internally use API::SerializedScriptValue (see APISerializedScriptValueCocoa.mm) use a JSContext to convert a JSValueRef to an Objective-C Foundation object. Creating the JSContext on an iPhone X with iOS 11.2 takes about 12~16ms and is significant relative to the other work API::SerializedScriptValue does.

The SharedJSContext class caches a JSContext to mitigate this overhead. However, the cache has a TTL of one second. This means that if one second elapses between calls to -[WKWebView evaluateJavaScript:completionHandler:], the previously cached JSContext is discarded and we pay the cost of creating a new one as well as a new JSVirtualMachine. You can observe this by timing sequential calls to -[WKWebView evaluateJavaScript:completionHandler:] -- they are generally under 1ms except for once a second when there is an extra 12~16ms.

If SharedJSContext were to cache its JSContext indefinitely (e.g., until a memory pressure event) or to cache the underlying JSVirtualMachine, it seems likely that the latency of WKWebView's calls would decrease and become more consistent, and noticeably improve the responsiveness of apps that make these calls in response to UI events.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20180326/00ee3458/attachment.html>


More information about the webkit-unassigned mailing list