You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Incarnadine (JIRA)" <ji...@apache.org> on 2014/12/23 01:36:14 UTC

[jira] [Updated] (CB-8207) [WKWebView][iOS 8] Unnecessary JSON conversion and possible leak

     [ https://issues.apache.org/jira/browse/CB-8207?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Incarnadine updated CB-8207:
----------------------------
    Description: 
The WKWebView bridge is calling JSON.stringify and adding the result to the command queue which appears to be unnecessary. 

The JSON conversion negates part of the performance gain of letting WKScriptMessage marshal the array.

Additionally, since commands with WKWebView are processed immediately, it's unclear what will happen to the queued commands. Something will either process them resulting in duplicate command execution, or the queue will continue to grow and allocate memory.

See ios/exec.js:

{code}
    // FIXME: This call may be unnecessary depending on how 
    // WKScriptMesssage marshals ArrayBuffer
    actionArgs = massageArgsJsToNative(actionArgs);

    var command = [callbackId, service, action, actionArgs];

    // FIXME: This is unnecessary with WKWebView binding
    // and should move into the else below
    commandQueue.push(JSON.stringify(command));
    
    if (bridgeMode === jsToNativeModes.WK_WEBVIEW_BINDING) {
        window.webkit.messageHandlers.cordova.postMessage(command);
    } else {
        if (!isInContextOfEvalJs && commandQueue.length == 1) {
            pokeNative();
        }
    }
{code}

  was:
The WKWebView bridge is calling JSON.stringify and adding the result to the command queue which appears to be unnecessary. 

The JSON conversion negates part of the performance gain of letting WKScriptMessage marshal the array.

Additionally, since commands with WKWebView are processed immediately, it's unclear what will happen to the queued commands. Something will either process them resulting in duplicate command execution, or the queue will continue to grow and allocate memory.

See ios/exec.js:

```
    // FIXME: This call may be unnecessary depending on how 
    // WKScriptMesssage marshals ArrayBuffer
    actionArgs = massageArgsJsToNative(actionArgs);

    var command = [callbackId, service, action, actionArgs];

    // FIXME: This is unnecessary with WKWebView binding
    // and should move into the else below
    commandQueue.push(JSON.stringify(command));
    
    if (bridgeMode === jsToNativeModes.WK_WEBVIEW_BINDING) {
        window.webkit.messageHandlers.cordova.postMessage(command);
    } else {
        if (!isInContextOfEvalJs && commandQueue.length == 1) {
            pokeNative();
        }
    }
```


> [WKWebView][iOS 8] Unnecessary JSON conversion and possible leak
> ----------------------------------------------------------------
>
>                 Key: CB-8207
>                 URL: https://issues.apache.org/jira/browse/CB-8207
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 3.5.0
>            Reporter: Incarnadine
>
> The WKWebView bridge is calling JSON.stringify and adding the result to the command queue which appears to be unnecessary. 
> The JSON conversion negates part of the performance gain of letting WKScriptMessage marshal the array.
> Additionally, since commands with WKWebView are processed immediately, it's unclear what will happen to the queued commands. Something will either process them resulting in duplicate command execution, or the queue will continue to grow and allocate memory.
> See ios/exec.js:
> {code}
>     // FIXME: This call may be unnecessary depending on how 
>     // WKScriptMesssage marshals ArrayBuffer
>     actionArgs = massageArgsJsToNative(actionArgs);
>     var command = [callbackId, service, action, actionArgs];
>     // FIXME: This is unnecessary with WKWebView binding
>     // and should move into the else below
>     commandQueue.push(JSON.stringify(command));
>     
>     if (bridgeMode === jsToNativeModes.WK_WEBVIEW_BINDING) {
>         window.webkit.messageHandlers.cordova.postMessage(command);
>     } else {
>         if (!isInContextOfEvalJs && commandQueue.length == 1) {
>             pokeNative();
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org