jurassic icon indicating copy to clipboard operation
jurassic copied to clipboard

Performance issue during first script execution on Azure cloud service

Open genna opened this issue 9 years ago • 1 comments

Hi,

I have a big JS script which looks like

function executeScript(param1, param2) {
    // It's about 1000 lines of code here
}

During the first run I compile the script and put FunctionInstance to a cache to be able to reuse it in future:

var engine = new ScriptEngine
{
    EnableExposedClrTypes = true
};
var compiledScript = engine.Compile(new StringScriptSource(script));
compiledScript.Execute();
var executeScriptFunc = (FunctionInstance)engine.GetGlobalValue("executeScript");

cache.Add('SCRIPT_ID', executeScriptFunc);

After that I execute the function like this:

Trace.TraceInformation($"{DateTime.Now:T} => Before");

var result = executeScriptFunc.Call(null, "Some value 1", "Some value 2");

Trace.TraceInformation($"{DateTime.Now:T} => After");

On any local environment, the first run takes about 1.5 sec to start executing the first line of the script. Further runs don't have this lag at all

But if I deploy the same code to Azure cloud service, the first run takes about 5 minutes. It doesn't depend on how powerful Azure cloud service is. It's always about 5 minutes. Second and future runs are immediate.

For second and further runs I use cached FunctionInstance

Don't you guys know why it happens? Where could I look at to fix this?

genna avatar Jul 22 '16 09:07 genna

I have no idea, sorry. Possibly it doesn't like the way Jurassic does code generation? Try setting EnableDebugging = true (before you call Compile()) and see if it makes a difference.

paulbartrum avatar Sep 13 '16 02:09 paulbartrum