Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow EvaluateCast #153

Open
raikilon opened this issue Sep 14, 2022 · 1 comment
Open

Slow EvaluateCast #153

raikilon opened this issue Sep 14, 2022 · 1 comment

Comments

@raikilon
Copy link

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?

@froggy96
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants