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.
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.
This could also be a record.
| _resolver = resolver; | ||
| } | ||
|
|
||
| public override bool Equals(object other) |
There was a problem hiding this comment.
Why does the resolver need this if you're always using the singleton?
dmetzgar
left a comment
There was a problem hiding this comment.
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.
aoltean16
left a comment
There was a problem hiding this comment.
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.