-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add an option to tag helper providers to allow filtering #29688
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
Conversation
As part of converting to source generators, one of the features we miss from MSBuild is the ability to no-op and cache results operations if inputs are unchanged (target incrementalism). In this particular case, we're trying to caching tag helper descriptors instead of discovering it every build. One fairly simple solution is to cache descriptors for reference assemblies (that typically remain unchanged between compilations), and the current assembly separately. The former can be cached and invalidated when metadatareferences change while the latter has a smaller set of types to search.
This comes up as part of source generation work. |
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.
Looks legit. Left some stuff inline.
{ | ||
// Arrange | ||
var testTagHelper = "TestAssembly.TestTagHelper"; | ||
var enumTagHelper = "Microsoft.CodeAnalysis.Razor.Workspaces.Test.EnumTagHelper"; |
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.
How does this EnumTagHelper
come in to play? I would expect that there is a project reference to Microsoft.CodeAnalysis.Razor.Workspaces.Test
somewhere but I am missing where that happens...
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.
The test compilation references the test project which has these types. It kinda simulates having a project reference like Mvc or Components.
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
#nullable enable |
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.
Do we need this here?
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.
Nullable everything!
} | ||
|
||
foreach (var reference in compilation.References) | ||
if ((discoveryMode & TagHelperDiscoveryFilter.ReferenceAssemblies) == TagHelperDiscoveryFilter.ReferenceAssemblies) |
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 we encapsulate these types of checks into two static methods: ShouldDiscoverFromReferenceAssemblies
and ShouldDiscoverFromAppAssembly
or something?
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.
If I were to create a method, it's tempting to also put the lookup inside the code which now results in an extra dictionary lookup per call. In the absence of it, it's a simple enum check, which seems like an overkill to have a method for.
As part of converting to source generators, one of the features we miss from MSBuild is the ability to no-op and cache
results operations if inputs are unchanged (target incrementalism). In this particular case, we're trying to
caching tag helper descriptors instead of discovering it every build.
One fairly simple solution is to cache descriptors for reference assemblies (that typically remain unchanged between compilations),
and the current assembly separately. The former can be cached and invalidated when metadatareferences change while the latter has a smaller set of types to search.