I'd suggest doing mScope.PH = editScope. That will create a rule which will
get cached and will generally run faster than passing the string directly.
The only other thing I can think of is maybe there's something odd w/ rule
being produced because "editScope" is a dynamic object in SetupEdit so
"mScope.SetVariable("PH", editScope);" ends up dispatching dynamically. If you
did "mScope.SetVariable("PH", (object)editScope);" it would dispatch statically.
If neither of those solutions helps I can see if I can look deeper and see if I
can repro it. There were some issues w/ IronPython 2.6 where this was really
slow but they should have been fixed w/ 2.6.1.
From: [email protected]
[mailto:[email protected]] On Behalf Of Cory Brostowicz
Sent: Thursday, August 12, 2010 7:34 AM
To: [email protected]
Subject: [IronPython] ScriptScope.SetVariable() performance
Hello,
I'm trying to get more performance out of my IronPython scripts inside one of
my applications, and noticed I'm spending the bulk of my time setting up the
ScriptScope prior to execution. My applications translates information coming
from a flat file, and I use IronPython to enforce business rules on various
records that I pull from my input file. The object that I'm passing to the
scope is custom implementation of the ExpandoObject.
Am I doing anything out of the ordinary here, or is there a better way to get
the performance I'm after? It doesn't seem like setting up the script should
performance significantly slower than executing the script itself.
Here is an example of the performance results I'm getting. I'm keeping track
of various timings for execution time, but the script setup timer is really
just stopping and starting a stopwatch before and after each call to
ScriptScope.SetVariable()...
DUMPING EDIT STATS
------------------
Edit: SetProviderType Count: 70291 Min: 9.927000E-001 Max:
4.922160E+001 Total: 7.656987E+004 Setup: 4.667084E+005
Edit: SetFeeSchedule Count: 70291 Min: 1.572500E+000 Max:
6.547200E+001 Total: 1.067754E+005 Setup: 4.639014E+005
Edit: phDefaultNetworkCode Count: 70291 Min: 1.900000E-002 Max:
2.413129E+002 Total: 1.618541E+003 Setup: 1.161743E+002
Edit: phCloneFieldList Count: 70291 Min: 4.400000E-003 Max:
4.083400E+000 Total: 3.565259E+002 Setup: 1.113712E+002
Edit: phAssignValueToField Count: 70291 Min: 9.700000E-003 Max:
1.777100E+000 Total: 5.765196E+002 Setup: 1.108866E+002
SetProviderType and SetFeeSchedule are both IronPython scripts, the other three
are C# edits that I'm passing my ExpandoObject directly to.
4.667 E+005 = almost 8 minutes...
1.108 E+002 = .1 seconds
Thanks in advance for any advice you can help me with.
-Cory
class IronPythonScriptHost : PrimeEditBase {
ScriptSource mScriptSource;
ScriptEngine mEngine;
ScriptScope mScope;
public IronPythonScriptHost(string scriptText, string
ScriptName, CommandLine mCommandLine, string[] mEditParms, ScriptEngine engine)
: base(mCommandLine, mEditParms) {
mEditName = ScriptName;
mIsScript = true;
mEngine = engine;
mScriptSource =
mEngine.CreateScriptSourceFromString(scriptText,
Microsoft.Scripting.SourceCodeKind.File);
mScriptSource.Compile();
mScope = mEngine.CreateScope();
}
public override void SetupEdit(dynamic editScope) {
StartSetupTimer();
mScope.SetVariable("PH", editScope);
StopSetupTimer();
}
public override void performEdit() {
StartExecutionTimer();
try {
mScriptSource.Execute(mScope);
CleanupEdit();
} catch (Exception ex) {
ExceptionOperations ExcOps =
mEngine.GetService<ExceptionOperations>();
throw new Exception("Exception
during execution of " + base.EditName + ". " + ex.Message + "\r\n" +
ExcOps.FormatException(ex));
}
StopAndRecordExecutionTimer();
}
}
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com