Skip to content

Compute Java name hashes on demand instead of pre-computing both#11132

Merged
jonathanpeppers merged 1 commit intomainfrom
jonathanpeppers/dev-peppers-hash-java-names-on-demand
Apr 17, 2026
Merged

Compute Java name hashes on demand instead of pre-computing both#11132
jonathanpeppers merged 1 commit intomainfrom
jonathanpeppers/dev-peppers-hash-java-names-on-demand

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Both MonoVM and CoreCLR type mapping generators were pre-computing
32-bit and 64-bit Java name hashes during Construct(), even though
only one width is ever used per architecture target. Since each ABI gets
its own generator instance (the data is not shared across
android-arm/android-arm64/android-x86/android-x64), the unused hash was
pure overhead.

This PR replaces JavaNameHash32/JavaNameHash64 with a single
ulong JavaNameHash field and moves the computation into
GenerateAndSortJavaHashes(), where target.Is64Bit is already known.
The two separate comparers (JavaNameHash32Comparer /
JavaNameHash64Comparer) are collapsed into one JavaNameHashComparer.

The CLR generator's HashJavaNames() also built HashSet<uint> and
HashSet<ulong> locals that were never read -- those are removed as
well.

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests -- existing tests cover this; no new tests needed.

Replace JavaNameHash32/JavaNameHash64 with a single JavaNameHash field in
both MonoVM and CoreCLR type mapping generators. Hashes are now computed
on demand in GenerateAndSortJavaHashes() where the target is known,
instead of pre-computing both 32-bit and 64-bit hashes during Construct().

Since each architecture gets its own generator instance, only one hash
width is ever needed. This eliminates redundant computation and storage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 19:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces typemap generator overhead by computing Java type name hashes only for the target bitness being emitted (32-bit or 64-bit), instead of always computing both during construction. This affects both the MonoVM and CoreCLR typemap native assembly generators in Xamarin.Android.Build.Tasks.

Changes:

  • Replace JavaNameHash32/JavaNameHash64 with a single ulong JavaNameHash in both generators.
  • Move hash computation and Java map sorting into GenerateAndSortJavaHashes() where target.Is64Bit is known, and collapse the two hash comparers into one.
  • Remove unused local HashSet<uint> / HashSet<ulong> allocations in the CLR generator’s removed hashing path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Xamarin.Android.Build.Tasks/Utilities/TypeMappingReleaseNativeAssemblyGenerator.cs Compute/sort Java name hashes per-target in GenerateAndSortJavaHashes(), use a single hash field and comparer, and remove eager dual-hash computation.
src/Xamarin.Android.Build.Tasks/Utilities/TypeMappingReleaseNativeAssemblyGeneratorCLR.cs Same on-demand per-target hash computation/sort refactor for the CoreCLR generator; removes unused hash set locals from the deleted hashing method.

Copy link
Copy Markdown
Member

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

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

CI failures are unrelated.

@jonathanpeppers jonathanpeppers merged commit 5c2a50b into main Apr 17, 2026
9 of 10 checks passed
@jonathanpeppers jonathanpeppers deleted the jonathanpeppers/dev-peppers-hash-java-names-on-demand branch April 17, 2026 13:50
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.

3 participants