Skip to content

Use IsEditorRequired in Equality checks #33553

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
Jun 15, 2021
Merged

Conversation

pranavkm
Copy link
Contributor

No description provided.

@pranavkm pranavkm requested a review from Pilchie as a code owner June 15, 2021 16:30
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jun 15, 2021
@pranavkm pranavkm requested review from NTaylorMullen and a team June 15, 2021 16:30
@@ -8,7 +8,7 @@

namespace Microsoft.AspNetCore.Razor.Language
{
internal class BoundAttributeDescriptorComparer : IEqualityComparer<BoundAttributeDescriptor>
internal sealed class BoundAttributeDescriptorComparer : IEqualityComparer<BoundAttributeDescriptor>
Copy link
Member

Choose a reason for hiding this comment

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

Seeing how much sealed shows up in @pranavkm's PRs, I propose renaming it to "the Pranav modifier".

Copy link
Contributor

Choose a reason for hiding this comment

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

#pranavPoints 😄

@SteveSandersonMS SteveSandersonMS self-requested a review June 15, 2021 16:50
Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

I guess you're fixing something specific here, but I can't guess what. I'm interested to know, but either way, the changes look totally reasonable.

@pranavkm
Copy link
Contributor Author

pranavkm commented Jun 15, 2021

I'm interested to know, but either way, the changes look totally reasonable.

I discovered it as part of https://github.com/dotnet/aspnetcore-tooling/pull/3798/files. I had initially thought that the property would necessarily matter for comparison, but there's some sort of caching that is performed by tooling: https://github.com/dotnet/aspnetcore-tooling/blob/main/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/TagHelperDescriptorCache.cs#L8 which tripped up a test.

@pranavkm pranavkm enabled auto-merge (squash) June 15, 2021 17:19
Comment on lines 53 to 54
{
if (descriptor == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially worth adding this to ensure the TagHelper caching mechanism is able to differentiate between two similar taghelpers with different IsEditorRequired values.

hash.Add(descriptor.IsEditorRequired);

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, you'll need this to get around the caching as it's based on hash code and not equality. Disabling auto-merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh fun, I missed that. Do you know how it works for properties like IsEnum that aren't enumerated here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend adding in all uniquely identifiable properties into this GetHashCode. I tried to strike a balance between identifiable properties and simplicity (to ensure hashing doesn't add any substantial cost).

Hashing PR: #24551
Perf Benchmarks: dotnet/razor#2307

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But isn't the caching already busted at that point? In general though, it seems very problematic to use a hash to cache items. A hash isn't guaranteed to be unique. If tooling wanted to ensure this behavior, it should write it's own comparer that guarantees it's requirements.

Copy link
Contributor

@TanayParikh TanayParikh Jun 15, 2021

Choose a reason for hiding this comment

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

Hashing is imperfect, but it was the tradeoff between accuracy and perf. Assuming enough entropy in the hash (by covering the subset of unique properties) chances of a hash collision should be minimal. Without this caching each GetTagHelpers call through Roslyn is going to cost ~230 tag helper allocations. And this is a fairly frequent call (IIRC occurs during compilations).

Going the comparator route would ensure accuracy but would undermine much of the perf benefits (as we'd still need to do a bunch of allocations and so on in order to subsequently do the comparisons on the tooling end). Right now if we match the hash within the cache, we skip deserializing/allocating the rest of the taghelper.

Copy link
Contributor Author

@pranavkm pranavkm Jun 15, 2021

Choose a reason for hiding this comment

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

Right - but you get incorrect results with the current implementation. Correctness > perf.

@TanayParikh TanayParikh disabled auto-merge June 15, 2021 17:27
@pranavkm pranavkm merged commit 767793b into main Jun 15, 2021
@pranavkm pranavkm deleted the prkrishn/iseditorrequired branch June 15, 2021 18:48
@ghost ghost added this to the 6.0-preview6 milestone Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants