-
Notifications
You must be signed in to change notification settings - Fork 219
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
Improve first invoke performance #260
base: develop
Are you sure you want to change the base?
Conversation
The first `Invoke()` call is slow. When the xaml file contains a lot of VB scripts, JIT compiler will be used, but for **every** compilation, the compiler starts from the scratch and always tries to resolve missing references via `MetadataReference.CreateFromFile`, thus it will be very slow. With some test cache between compilations, one of our test xaml file is improved from 18s to 3.5s.
|
||
ScriptMetadataResolver _resolver; | ||
|
||
private class ResolveCacheKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use a record for this instead? It already has equals and hashcode implementations that do very similar things to what you're doing here.
} | ||
ConcurrentDictionary<ResolveCacheKey, ImmutableArray<PortableExecutableReference>> _resolveCache = new ConcurrentDictionary<ResolveCacheKey, ImmutableArray<PortableExecutableReference>>(); | ||
|
||
private class ResolveMissingCacheKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be a record.
_resolver = resolver; | ||
} | ||
|
||
public override bool Equals(object other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the resolver need this if you're always using the singleton?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR and apologies for the delay in reviewing. If you still want to go forward, this code seems it could be a lot simpler using records. There are enough custom hash code implementations in WF and I'd like to avoid adding another one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide an unit test or benchmark showcasing the issue and the improvement.
Thank you!
The first
Invoke()
call is slow. When the xaml file contains a lot of VB scripts, JIT compiler will be used, but for every compilation, the compiler starts from the scratch and always tries to resolve missing references viaMetadataReference.CreateFromFile
, thus it will be very slow. With some test cache between compilations, one of our test xaml file is improved from 18s to 3.5s.