ExpressionEvaluator icon indicating copy to clipboard operation
ExpressionEvaluator copied to clipboard

Slow EvaluateCast

Open raikilon opened this issue 3 years ago • 1 comments

After upgrading to the last version from 1.4.16.0 we are encountering performance issues on the EvaluateCast function.

image

The slowdown is caused by the use of the EvaluateType method instead of the GetTypeByFriendlyName.

image

Is this normal?

raikilon avatar Sep 14 '22 08:09 raikilon

I had similar issues and finally found out for my case. I hope this could be at least a hint for your case.

In my case, Assemblies loads many DLLs from my AppDomain (as my solution contains many DLLs)

So, I tried to remove all unnecessary DLLs being loaded.

var engine = new ExpressionEvaluator();

        // load assemblies needed for script
        engine .Assemblies.Clear();
        engine .Assemblies.Add(Assembly.Load("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
        engine .Assemblies.Add(Assembly.Load("MyDLL1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
        engine .Assemblies.Add(Assembly.Load("MyDLL2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));

        // add namespaces 
        engine .Namespaces.Add("MyLib.MyClass");
        engine .Namespaces.Add("MyLib2.MyClass2");

        // add types
        engine .Types.Add(typeof(MyLib.MyClass));
        engine .Types.Add(typeof(MyLib2.MyClass2));

        // then call evaluator

var result = eingine.ScriptEvaluate(engine.RemoveComments(expression));

after doing this, > 500ms total time reduced to 31ms

Hope this helps!

froggy96 avatar Nov 12 '22 01:11 froggy96