Skip to content

[CoreCLR] Attempt to replace xxhash with crc32#12013

Draft
simonrozsival wants to merge 15 commits into
dotnet:mainfrom
simonrozsival:dev/simonrozsival/coreclr-typemap-crc32
Draft

[CoreCLR] Attempt to replace xxhash with crc32#12013
simonrozsival wants to merge 15 commits into
dotnet:mainfrom
simonrozsival:dev/simonrozsival/coreclr-typemap-crc32

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Jul 7, 2026

Copy link
Copy Markdown
Member

Goal

Remove the CoreCLR native dependency on xxHash/constexpr-xxh3 in .NET for Android lookup paths while preserving runtime behavior and startup performance. The primary improvement is dependency removal; app size and startup time are expected to be unchanged within measurement noise.

Summary

  • replace CoreCLR LLVM typemap xxHash lookups with CRC32 hashes from System.IO.Compression.Native
  • replace CoreCLR assembly-store name hashes with 32-bit CRC32 and bump the CoreCLR store format to v4
  • replace CoreCLR DSO APK/cache hashes with 32-bit CRC32
  • replace CoreCLR dynamic and precompiled p/invoke override hashes with 32-bit CRC32
  • keep MonoVM assembly stores and MonoVM runtime lookup data on the existing xxHash layout
  • move xxHash-specific Search helpers to MonoVM so CoreCLR no longer includes shared/xxhash.hh through common search.hh
  • remove external/xxHash and constexpr-xxh3 include paths from CoreCLR native CMake targets
  • remove CoreCLR-only dead paths exposed by the cleanup: AOT DSO cache, debug typemap string fallback switch, duplicate runtime-property hash index, and runtime-property host callback
  • update generated-layout test parsing and the mk2 store reader for the new CoreCLR layouts
  • keep typemap lookups collision-safe by comparing original managed/Java names after matching the hash

Benchmark

CoreCLR MAUI Release/R2R sample, Android arm64, Samsung SM-A165F, interleaved runs, no reboot. The comparison below uses #12010 as the xxHash baseline because it contains the p/invoke resolver cleanup needed to run with the current runtime packs; this isolates the CRC32/dependency-removal changes in this PR.

Size

Variant APK size libmonodroid.so uncompressed
#12010 baseline / xxHash 30,693,198 B 1,247,192 B
#12013 current / CRC32 30,709,582 B 1,250,616 B

Startup, 30x mixed cold + hot, IQR outliers removed

Mode #12010 baseline mean / median #12013 current mean / median Delta
Cold WaitTime 2005.0 / 1998 ms 1998.7 / 1995 ms -6.3 ms mean, -3 ms median
Hot WaitTime 148.2 / 146.5 ms 148.1 / 148 ms -0.1 ms mean, +1.5 ms median

Result: app size and startup times are unchanged within measurement noise. The meaningful win is removing CoreCLR's dependency on the xxHash/constexpr-xxh3 native dependency chain.

Validation

  • dotnet build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj -v:minimal
  • dotnet build tools/assembly-store-reader-mk2/assembly-store-reader.csproj -v:minimal
  • dotnet build src/native/native-clr.csproj -m:1 -p:AndroidSupportedTargetJitAbis=arm64-v8a -v:minimal
  • dotnet build src/native/native-mono.csproj -m:1 -p:AndroidSupportedTargetJitAbis=arm64-v8a -v:minimal
  • dotnet build src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj -v:minimal
  • clean CoreCLR native arm64 configure/build after removing xxHash include paths; compile output contains no external/xxHash or external/constexpr-xxh3 include paths
  • direct CreateAssemblyStore probe generated a CoreCLR Arm64 v4 store with 9-byte index entries and the mk2 reader opened it successfully
  • CoreCLR MAUI benchmark APKs built and launched on Samsung SM-A165F

simonrozsival and others added 2 commits July 8, 2026 00:02
Replace CoreCLR LLVM typemap xxHash lookups with CRC32 hashes from System.IO.Compression.Native. Keep collision-safe lookup by comparing the original managed or Java type name after matching the hash.

This is a first step toward removing the CoreCLR xxHash dependency to reduce size while preserving runtime lookup performance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Emit CoreCLR assembly stores with 32-bit CRC32 name hashes and update the CoreCLR native assembly-store lookup to use the shared CRC32 helper.

Keep MonoVM assembly stores on the existing xxHash layout, bump the CoreCLR store format to v4, and update the mk2 store reader to infer index entry width from the header index size.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival changed the title [coreclr] Use CRC32 for LLVM typemap hashes [coreclr] attempt to replace xxhash with crc32 Jul 7, 2026
simonrozsival and others added 2 commits July 8, 2026 00:38
Replace CoreCLR runtime property, DSO APK, and DSO/AOT cache xxHash lookups with CRC32 hashes from the shared native CRC32 helper.

Update generated CoreCLR app config, desktop app stub data, and strict generated-layout test parsing for the smaller 32-bit hash fields.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Switch the CoreCLR dynamic p/invoke override and generated find_pinvoke tables to 32-bit CRC32 hashes.

Keep the precompiled p/invoke table on the existing xxHash layout while removing xxHash from the shared p/invoke override header and fallback cache path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival simonrozsival changed the title [coreclr] attempt to replace xxhash with crc32 [CoreCLR] Attempt to replace xxhash with crc32 Jul 7, 2026
simonrozsival and others added 10 commits July 8, 2026 01:44
Switch the CoreCLR precompiled p/invoke override table and generator to 32-bit CRC32 hashes.

This removes the remaining CoreCLR p/invoke override dependency on xxHash while keeping the table collision check in the generator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the common Search helper generic-only and move the xxHash-specific overloads to a MonoVM-only search-xxhash.hh wrapper.

This prevents CoreCLR native code from including shared/xxhash.hh through the common search helper while preserving MonoVM's existing hash_t search callsites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Stop adding external/xxHash and constexpr-xxh3 include paths to CoreCLR native targets now that CoreCLR no longer includes shared/xxhash.hh.

Keep the xxHash include support available for MonoVM and NativeAOT paths that still use it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Introduce a CoreCLR-local hash_t alias to uint32_t in the CRC32 helper and use it for CoreCLR hash fields, lookup signatures, and generated p/invoke tables.

This keeps the code readable without reintroducing the shared xxHash wrapper or changing MonoVM's hash_t layout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a compile-time crc32_hash overload for string literals and use it in CoreCLR generated/default tables instead of hardcoded hex hash values.

This keeps the generated p/invoke table and app stub self-documenting while preserving the runtime CRC32 helper for dynamic strings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allow generated-environment tests to parse decimal uint32 values above Int32.MaxValue and update CoreCLR APK size baselines after the CRC32 native size changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the CoreCLR debug typemap string fallback now that CRC32 lookups verify matching strings, and remove the unused CoreCLR AOT DSO cache path while failing fast if a CoreCLR config tries to use it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse the runtime property arrays passed to coreclr_initialize for the host runtime contract callback instead of emitting a duplicate CRC32-indexed lookup table.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Leave the host runtime contract in place for p/invoke and assembly probing, but set get_runtime_property to null because Android passes runtime configuration through coreclr_initialize and the callback only produced negative host-property probes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove unused CoreCLR application config structure-info fields that were only kept for potential future host configuration data.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@simonrozsival

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant