Skip to content

Update the conventions for discovering and invoking metadata update handlers #17460

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

Merged
merged 2 commits into from
May 6, 2021

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented May 5, 2021

  • Introduce ClearCache and UpdateApplication action names
  • Invoke actions in topologically sorted order.

Contributes to dotnet/runtime#51545

…andlers

* Introduce ClearCache and UpdateApplication action names
* Invoke actions in topologically sorted order.
@ghost
Copy link

ghost commented May 5, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

// This would ensure that there is a well-defined order and that caches and updates more lower in the application stack
// are up to date before ones higher in the stack are recomputed.
var assemblies = GetAssembliesWithMetadataUpdateHandlerAttributes();
var sortedAssemblies = TopologicalSort(CollectionsMarshal.AsSpan(assemblies));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point in using CollectionsMarshal.AsSpan here. Change it to use a regular enumerator instead.

The potentially dangerous APIs like ``CollectionsMarshal.AsSpan` are meant to be only used for core that needs to be micro-optimized to the last cycle. It is not the case here. You are calling GetCustomAttributes inside the loop that is like 1000x times more expensive than the foreach.


static void Visit(ReadOnlySpan<Assembly> assemblies, Assembly assembly, List<Assembly> sortedAssemblies, HashSet<string> visited)
{
var assemblyIdentifier = assembly.FullName ?? assembly.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var assemblyIdentifier = assembly.FullName ?? assembly.ToString();
var assemblyIdentifier = assembly.FullName!;

Runtime loaded assemblies always have non-empty full names. This is just nullability annotations not being helpful.


foreach (var item in deltas)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was wrong with foreach ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it updated to use a local and I was worried I would get complaints about capturing delegates. I reverted it - the original version had less code 👍🏽

Copy link
Contributor Author

@pranavkm pranavkm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is updated.

Also sent dotnet/runtime#52409 to update the runtime to use the new names


foreach (var item in deltas)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it updated to use a local and I was worried I would get complaints about capturing delegates. I reverted it - the original version had less code 👍🏽

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pranavkm pranavkm enabled auto-merge (squash) May 6, 2021 22:34
@pranavkm pranavkm merged commit 04debec into main May 6, 2021
@pranavkm pranavkm deleted the prkrishn/topological branch May 7, 2021 00:04
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.

2 participants