Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Jul 29, 2025

This version exposes the XxHash128 class, which our Checksum class uses extensively. This and four other files that were copied into roslyn for it's support are no longer needed.

Test insertion pipeline run 1: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_build/results?buildId=12064988&view=results
-- failed miserably

Test inseriton pipeline run 2: https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_build/results?buildId=12066383&view=results

…package version

This version exposes the XxHash128 class, which our Checksum class uses extensively. This and four other files that were copied into roslyn for it's support are no longer needed.
length -= 4;
hash1 = (RuntimeBitOperations.RotateLeft(hash1, 5) + hash1) ^ (p0 | NormalizeToLowercase);
hash2 = (RuntimeBitOperations.RotateLeft(hash2, 5) + hash2) ^ (p1 | NormalizeToLowercase);
hash1 = (RotateLeft(hash1, 5) + hash1) ^ (p0 | NormalizeToLowercase);
Copy link
Member

@tmat tmat Jul 29, 2025

Choose a reason for hiding this comment

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

Wouldn't it be better to use System.Numerics.BitOperations.RotateLeft? It's a JIT intrinsic on dotnet.
We can define static extension polyfill for net472

Copy link
Contributor Author

@ToddGrun ToddGrun Jul 29, 2025

Choose a reason for hiding this comment

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

I have problems with the netstandard build when I tried this:

image

Go to definition on it in that context yields the following from the System.Collections.Immutable package:

namespace System.Numerics
{
#if !NET
    internal static class BitOperations
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static uint RotateLeft(uint value, int offset) => (value << offset) | (value >> (32 - offset));
    }
#endif
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dur, just read your comment again and went ahead and did that in commit 2


NotAscii:
return s_comparer.GetHashCode(obj);

Copy link
Member

@tmat tmat Jul 30, 2025

Choose a reason for hiding this comment

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

I'd add BitOperations to MS.CA.Contracts project. Similar to https://github.com/dotnet/roslyn/blob/main/src/Dependencies/Contracts/ValueTaskExtensions.cs.

That way we can call the dotnet version directly and net472 polyfill will be applied as needed.

-->
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Condition="'$(DotNetBuildSourceOnly)' != 'true'" PrivateAssets="ContentFiles" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.IO.Hashing" />
Copy link
Member

Choose a reason for hiding this comment

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

Hm, adding a new reference to compiler packages might cause problems. cc @jaredpar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is an issue at all, I'm definitely fine closing out this PR as this was just an attempt to remove some hashing code we had copied from the runtime, as I'm attempting to copy some of this code over to razor.

There are VS hurdles to clear if this change were to go forward too, as the test insertion is complaining about optimization data not found for System.IO.Hashing.dll

@tmat indicated he has some context with a similar earlier attempt, so it might be nice to get his input on the difficulties he encountered and whether he thinks this is worth pursuing.

Copy link
Member

Choose a reason for hiding this comment

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

At the very least we should make sure the new DLL is part of the toolset compiler package but I guess it is if it's being inserted into VS. There might be other infra considerations I'm missing though.

Copy link
Member

Choose a reason for hiding this comment

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

Adding a new DLL to the compiler dependency is not cheap. Want to avoid this unless there are significant gains.

Copy link
Member

@tmat tmat Aug 4, 2025

Choose a reason for hiding this comment

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

The gains were already attained. Switching to System.IO.Hashing pays off debt as discussed here: #70808

Copy link
Member

Choose a reason for hiding this comment

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

Can you forward me the approval?

Copy link
Member

Choose a reason for hiding this comment

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

I really hope we take this. The original copying of code was such an unpleasant hack to work around issues. It was really only meant to be temporary (as can even be seen in the conversation on my PR where we introduced this :)).

I definitely want us to be in the place where if the runtime creates and owns high perf algorithms like this, we can just naturally use them instead of effectively rolling our own :)

Copy link
Member

Choose a reason for hiding this comment

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

If we have the approval I'm okay with taking it for dev18. Just want to make sure we have it before we merge. Haven't seen it yet.

Let me know if was sent and I just missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tmat -- Can you forward any conversations you've previously had about this approval to this group?

Copy link
Member

Choose a reason for hiding this comment

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

@ToddGrun forwarded the exception request to this group. Think we can close on that being an issue.

@AlekseyTs
Copy link
Contributor

I think features/extensions adds some usages of hashing, please make sure this change is not going to break that branch

@JoeRobich
Copy link
Member

@ToddGrun Looking at the second test insertion and I see "No optimization data found" for System.IO.Hashing. I believe a <_NoOptimizationData Include="$(ArtifactsBinDir)csi\$(Configuration)\net472\System.IO.Hashing.dll"/> entry needs to be added to DesktopCompilerArtifacts.targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants