• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

[Q] CEP plugin response issue when Illustrator is in background. Any solution?

Contributor ,
Jun 22, 2017 Jun 22, 2017

Copy link to clipboard

Copied

Hi,

This is refined question with minimized issue code from following.

It happens only on background about 1-2 times in 1 minutes.

Regularly evalScript() takes 20-50 ms, but it got slow 2-5 sec.

It's like stop breathing in sleep.

While this stop breathing happening, bring Illustrator back on foreground and

do massive number of evalScript() call made, it become almost does not responds at all.

It's like a heart attack.

When the heart attack happened, the cure is call $.gc() from ExtendScript Tool Kit.

So following code has $.gc() included, but it seems not working from CEP code.

It might be related with following

Re: ID CC 2014 plus ExtendScript (Yosemite) slow to the point of not working...

The solution may not work as current code is targeting end user environment.

But if we can identified bottle neck process, we may be able to do something.

So is there any way we can do to prevent above stop breathing issue?

I think it could be minor issue, but it may lead to the heart attack issue.

Screenshot:

pollCounter = 319 is issue.

every 1 sec polling.

Screen Shot 2017-06-22 at 8.44.58 AM.png

pollCounter = 201 and 212 has issue.

Screen Shot 2017-06-22 at 8.42.48 AM.png

Test code is from modified from following.

CEP-Resources/CEP_7.x/Samples/CEP_HTML_Invisible_Extension-7.0 at master · Adobe-CEP/CEP-Resources ·...

Modified part in index.html

index.html

var illustrator = null;

var pollCounter = 0; // for throttling

var pollVariable = null;

var csi = new CSInterface();

function AiSupport(enabled) {

    this.inPoll    = false; // waiting for poll() response

    this.isMac     = (navigator.platform == "MacIntel");

}

window.onload = function() {

var host = csi.getHostEnvironment();

    if (host.appId == "ILST") {

        loadJSX("AiActionsTest.jsx"); // min version

        illustrator = new AiSupport(false);

    }

    pollVariable = setInterval(function() {

    poll();

     // }, 100); // 100ms

     }, 1000); // 1000ms

}

window.onunload = function() {

};

function loadJSX(fileName) {

    var csInterface = new CSInterface();

    var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";

    csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');

}

function poll() {

    //console.log('poll()');

    pollCounter++;

    pollAi();

}

function pollAi() {

    if (AiSupport.inPoll) {

        console.log('pollAi(): Skip to avoid duplicate request');

    } else {

        AiSupport.inPoll = true;

        console.log("pollAi(): getCurrentTool() request: pollCounter=", pollCounter);

        console.time("pollAi"); // performance measurement (NodeJs)

        csi.evalScript("aiGetSelectionType()", function (response) { // bypass for performance

            console.timeEnd("pollAi"); // performance measurement (NodeJs)

         console.log('response = ' + response);

            // other business logic

            AiSupport.inPoll = false;

        });

    }

}

function gcAi() {

    console.log('gcAi()');

    console.time("gcAi"); // performance measurement (NodeJs)

    csi.evalScript("$.gc()", function (response) {

        console.timeEnd("gcAi"); // performance measurement (NodeJs)

    });

}

AiActionsTest.jsx

// return selection data type

function aiGetSelectionType(){

    // $.writeln("aiGetSelectionType()"); // debug only

    $.hiresTimer; // reset

    $.gc(); // Garbage collector

    var result = "Unsupported";

    try{

        if(documents.length){

            var _sel = activeDocument.selection; // TextRange when Text chars are selected // faster than app.selection

            if("TextRange" == _sel.typename){ // Text char selected: OK: verifed working

                var _target = _sel;

                result = "TextRange";

            }else if(0 != _sel.length){ // Array: Single and Multiple items case

                // $.writeln("Number of selection = ", _sel.length); // debug only

                for(var i=0; i<_sel.length; i++){

                    if(i == 0){

                        result = _sel.typename;

                    }else{

                        if(result != _sel.typename){

                            //$.writeln("Got Mixed"); // debug only

                            result = "Mixed";

                            break;

                        }

                    }

                }

            }else{ // No selection

                // $.writeln("No selection == > Global mode"); // debug only

                result = "NoSelection";

            }

        }else{

            // no doc opened

        }

    }catch(e){

        $.writeln("EXCEPTION: ", e);

        if(aiDebugAlertException) alert("EXCEPTION: " + e);

    }

    $.writeln("aiGetSelectionType: result = ", result, " ", $.hiresTimer, " \xB5s"); // micro second

    return result;

}

I'll appreciate any tips and suggestion.

I made minimum code package to reproduce this issue.

Please let me know for the test code package.

Thank you,

Naoki

TOPICS
Scripting

Views

576

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jun 22, 2017 Jun 22, 2017

Copy link to clipboard

Copied

Hi,

I don't have any solution about that. However, We can use another callback mechanism.

Why don't you try to plugplugInterface like below?

1. Remove your evalScripts 2nd argument(callback function).

2. Add below event listener and new callback function.

//Javascript (HTML)

csi.addEventListener("getCallback", getReturnValue);

function getReturnValue(response) { // bypass for performance

  console.timeEnd("pollAi"); // performance measurement (NodeJs)

  console.log('response = ' + response.data);

  // other business logic

  AiSupport.inPoll = false;

  }

3. Replace last line(return result;) of your aiGetSelectionType function to below code.

//Extendscript

var xLib = new ExternalObject("lib:\PlugPlugExternalObject");

} catch (e) {

  alert(e);

  }

var eventObj = new CSXSEvent();

eventObj.type = "getCallback";

eventObj.data = result; //result must be String

if (app.activeDocument.selection.length>0){

  eventObj.data = app.activeDocument.selection[0].reflect.properties.length.toString();

  }

xLib.unload();

eventObj.dispatch();

You can reference below project.

https://github.com/ten-A/CreativeSuiteSDK_Experimentals/tree/master/net.sytes.chuwa.callbacktest

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

LATEST

Ten A​

Thank you very much for the tips and code.

I've tested with the PlugPlugExternalObject event handler.

Code itself worked fine.

But the response slowness still happening.

Another trying was disabling App Nap on Illustrator as commented previous post.

> Following seems working from short term testing and did not show any slowness..

>

>That is command to run in Terminal.

>After done, Illustrator need to restart.

>

>Turn off App Nap for Illustrator (not default setting)

>====

>defaults write com.adobe.illustrator NSAppSleepDisabled -bool true

>====

>

>Resume default: App Nap for Illustrator

>====

>defaults write com.adobe.illustrator NSAppSleepDisabled -bool false

>====

If there's other option other than above OS settings, it would be better.

Thank you,

Naoki

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines