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

Bad performance from CoreWF - no fast way to create a LambdaExpression from VB script code #68712

Closed
angelowang opened this issue Jun 21, 2023 · 4 comments
Labels
Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@angelowang
Copy link

Version Used:
4.0.1

Steps to Reproduce:
This is related to this CoreWF (the non-official port of Windows Workflow Foundation) issue: UiPath/CoreWF#208

  1. Due to the lack of VbHostedCompiler in .NET Framework, CoreWF has to use roslyn JIT compiler to emit DLL assembly from the script code, and then load the assembly to create a LambdaExpression. This is very slow.
  2. As we port our product to .NET 6, it sees significant performance degradation on the first run of the workflow. We are using CodeActivity a lot, so this VBScript to LambdaExpression is critical to us.
  3. According to Visual Basic scripting #13523, seems road map is not going that direction :(
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 21, 2023
@CyrusNajmabadi
Copy link
Member

Where is the time being spent in the code? Do you have any traces? Can yuo show how you're using roslyn here?

@angelowang
Copy link
Author

@CyrusNajmabadi I don't have trace now. This ticket has some similar callstack: UiPath/CoreWF#178

CoreWF is a open source WF porting (suppoted by .NET foundation). The code to compile VBScript to LambdaExpression is here:
VisualBasicValue is a CodeActivity, which will need to do the compiling from VBScript to LambdaExpression.
https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicValue.cs#L95
How it is compiled:
https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicDesignerHelper.cs#L77
https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Activities/ScriptingJitCompiler.cs#L77: accessing the ScriptClass method will do all the compiling
https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Activities/ScriptingAotCompiler.cs#L53: Finally an in-memory DLL is Emit'ed and loaded to create the LambdaExpression.

For one of our xaml file, the first time running the workflow degrades from 0.5s to 20s.
The problem with us is CodeActivity is used a lot, so there will be a lot of VisualBasicValue's which means a lot of expressions will be compiled. And every compiling is independent, and I've already tried to minimize the file access by caching MetadataReference in this UiPath/CoreWF#260, but still is 4s for the same file.

The .NET Framework has been using VbHostedCompiler, which is super fast.
Framework: https://github.com/microsoft/referencesource/blob/master/System.Activities/Microsoft/VisualBasic/Activities/VisualBasicHelper.cs#LL136C76-L136C76
NET6/CoreWF: https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Activities/JitCompilerHelper.cs#L1374, and https://github.com/UiPath/CoreWF/blob/develop/src/UiPath.Workflow/Microsoft/VisualBasic/Activities/VisualBasicSettings.cs#L49

@CyrusNajmabadi
Copy link
Member

I'm not really sure what in that code is using Roslyn. Can you collect a trace, see where the cost is, and we can perhaps figure out what team this should go to.

@angelowang
Copy link
Author

I will first close this one. It is actually a feature request like converting SyntaxTree to a LambdaExpression, instead of needing to compile to a dll first.
And there is some potential to improve it in CoreWF side too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants