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

Improve first invoke performance #260

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

angelowang
Copy link

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.

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor

@dmetzgar dmetzgar left a 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.

Copy link
Collaborator

@aoltean16 aoltean16 left a 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!

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

Successfully merging this pull request may close these issues.

None yet

3 participants