-
Notifications
You must be signed in to change notification settings - Fork 569
[TrimmableTypeMap] Use Crc64 package naming by default with LowercaseCrc64 compatibility #11193
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
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/update-hash-algorithm-to-xxhash64
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e1adf6
Initial plan
Copilot 9d16443
[TrimmableTypeMap] switch package hash generation to xxhash64
Copilot 174f08f
[TrimmableTypeMap] clarify hashed package helper naming
Copilot 1049678
[TrimmableTypeMap] switch generated package prefix to xx64
Copilot ec92067
[TrimmableTypeMap] support AndroidPackageNamingPolicy with XxHash64 d…
Copilot 8d5709b
[TrimmableTypeMap] reduce hashing allocations in JavaPeerScanner
Copilot 05cebc7
[TrimmableTypeMap] extract scanner hashing helper and scope defaults
Copilot 3722fd9
Merge remote-tracking branch 'origin/main' into copilot/update-hash-a…
Copilot e9ae72c
[TrimmableTypeMap] default trimmable policy to Crc64 and keep Lowerca…
Copilot fa8493d
[TrimmableTypeMap] remove xxhash64 path and improve Crc64 hashing buf…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/ScannerHashingHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| using System; | ||
| using Java.Interop.Tools.JavaCallableWrappers; | ||
|
|
||
| namespace Microsoft.Android.Sdk.TrimmableTypeMap; | ||
|
|
||
| internal static class ScannerHashingHelper | ||
| { | ||
| internal static string ToLegacyCrc64 (string ns, string assemblyName) | ||
| { | ||
| int byteCount = GetNamespaceAssemblyUtf8ByteCount (ns, assemblyName); | ||
| byte[] utf8Buffer = new byte [byteCount]; | ||
| int bytesWritten = GetNamespaceAssemblyUtf8Bytes (ns, assemblyName, utf8Buffer); | ||
| ulong crc = ulong.MaxValue; | ||
| ulong length = 0; | ||
| Crc64Helper.HashCore (utf8Buffer, 0, bytesWritten, ref crc, ref length); | ||
| Span<byte> hash = stackalloc byte [8]; | ||
| WriteUInt64LittleEndian (hash, crc ^ length); | ||
| return ToHexString (hash, lowercase: true); | ||
| } | ||
|
|
||
| internal static string ToCrc64 (string ns, string assemblyName) | ||
| { | ||
| const int stackallocThresholdBytes = 256; | ||
| int byteCount = GetNamespaceAssemblyUtf8ByteCount (ns, assemblyName); | ||
| Span<byte> utf8Buffer = byteCount <= stackallocThresholdBytes | ||
| ? stackalloc byte [stackallocThresholdBytes] | ||
| : new byte [byteCount]; | ||
|
|
||
| int bytesWritten = GetNamespaceAssemblyUtf8Bytes (ns, assemblyName, utf8Buffer.Slice (0, byteCount)); | ||
| Span<byte> hash = stackalloc byte [8]; | ||
| System.IO.Hashing.Crc64.Hash (utf8Buffer.Slice (0, bytesWritten), hash); | ||
| return ToHexString (hash, lowercase: true); | ||
| } | ||
|
|
||
| static int GetNamespaceAssemblyUtf8ByteCount (string ns, string assemblyName) | ||
| { | ||
| return System.Text.Encoding.UTF8.GetByteCount (ns) + 1 + System.Text.Encoding.UTF8.GetByteCount (assemblyName); | ||
| } | ||
|
|
||
| static unsafe int GetNamespaceAssemblyUtf8Bytes (string ns, string assemblyName, Span<byte> destination) | ||
| { | ||
| int bytesWritten = 0; | ||
| fixed (char* nsPtr = ns) | ||
| fixed (byte* destinationPtr = destination) { | ||
| bytesWritten += System.Text.Encoding.UTF8.GetBytes (nsPtr, ns.Length, destinationPtr, destination.Length); | ||
| } | ||
|
|
||
| destination [bytesWritten++] = (byte) ':'; | ||
|
|
||
| fixed (char* assemblyNamePtr = assemblyName) | ||
| fixed (byte* destinationPtr = destination) { | ||
| bytesWritten += System.Text.Encoding.UTF8.GetBytes (assemblyNamePtr, assemblyName.Length, destinationPtr + bytesWritten, destination.Length - bytesWritten); | ||
| } | ||
|
|
||
| return bytesWritten; | ||
| } | ||
|
|
||
| static string ToHexString (ReadOnlySpan<byte> hash, bool lowercase) | ||
| { | ||
| const int maxStackCharLength = 128; | ||
| int charLength = hash.Length * 2; | ||
| Span<char> chars = charLength <= maxStackCharLength | ||
| ? stackalloc char [charLength] | ||
| : new char [charLength]; | ||
|
|
||
| for (int i = 0, j = 0; i < hash.Length; i += 1, j += 2) { | ||
| byte b = hash [i]; | ||
| chars [j] = GetHexValue (b / 16, lowercase); | ||
| chars [j + 1] = GetHexValue (b % 16, lowercase); | ||
| } | ||
|
|
||
| return ((ReadOnlySpan<char>) chars).ToString (); | ||
| } | ||
|
|
||
| static void WriteUInt64LittleEndian (Span<byte> destination, ulong value) | ||
| { | ||
| destination [0] = (byte) value; | ||
| destination [1] = (byte) (value >> 8); | ||
| destination [2] = (byte) (value >> 16); | ||
| destination [3] = (byte) (value >> 24); | ||
| destination [4] = (byte) (value >> 32); | ||
| destination [5] = (byte) (value >> 40); | ||
| destination [6] = (byte) (value >> 48); | ||
| destination [7] = (byte) (value >> 56); | ||
| } | ||
|
|
||
| static char GetHexValue (int value, bool lowercase) | ||
| { | ||
| return (char) (value < 10 | ||
| ? value + '0' | ||
| : value - 10 + (lowercase ? 'a' : 'A')); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
XxHash64should be the default just for the trimmable typemapThere 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.
Addressed in 05cebc7: reverted the global
AndroidPackageNamingPolicydefault and scopedXxHash64as the default specifically for trimmable typemap generation.