Oh, yeah, objects aren't dynamic unless they're typed to dynamic :)  I guess it 
needs to be:
((dynamic)mScope).PH = editScope;


From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Cory Brostowicz
Sent: Thursday, August 12, 2010 10:11 AM
To: Discussion of IronPython
Subject: Re: [IronPython] ScriptScope.SetVariable() performance

I'm not sure what you mean by "mScope.PH = editScope".  mScope = ScriptScope 
and doesn't allow dynamic properties.

On the other hand, thanks for the suggestion with the object cast.  That gave 
brought my setup performance up to par with the native C# edits!

Edit: SetProviderType           Count: 70291   Min: 9.866000E-001 Max: 
5.393440E+001 Total: 6.684688E+004 Setup: 1.904770E+002
Edit: SetFeeSchedule            Count: 70291   Min: 1.229300E+000 Max: 
6.506160E+001 Total: 9.587090E+004 Setup: 1.747695E+002
Edit: phDefaultNetworkCode      Count: 70291   Min: 9.700000E-003 Max: 
2.347088E+002 Total: 1.154772E+003 Setup: 1.156382E+002
Edit: phCloneFieldList          Count: 70291   Min: 3.200000E-003 Max: 
4.007700E+000 Total: 2.727729E+002 Setup: 1.137180E+002
Edit: phAssignValueToField      Count: 70291   Min: 4.400000E-003 Max: 
1.205800E+000 Total: 4.475063E+002 Setup: 1.152221E+002

On Thu, Aug 12, 2010 at 11:42 AM, Dino Viehland 
<di...@microsoft.com<mailto:di...@microsoft.com>> wrote:
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: 
users-boun...@lists.ironpython.com<mailto:users-boun...@lists.ironpython.com> 
[mailto:users-boun...@lists.ironpython.com<mailto:users-boun...@lists.ironpython.com>]
 On Behalf Of Cory Brostowicz
Sent: Thursday, August 12, 2010 7:34 AM
To: users@lists.ironpython.com<mailto:users@lists.ironpython.com>
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
Users@lists.ironpython.com<mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to