dotnet / dotnet/android

Consider parallelizing GenerateTypeMappings across ABIs

Open
#11,131 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 21h
Merged PRs (30d)
257

Description

## Summary

`GenerateTypeMappings.GenerateAllTypeMappings()` processes each ABI sequentially:

https://github.com/dotnet/android/blob/main/src/Xamarin.Android.Build.Tasks/Tasks/GenerateTypeMappings.cs#L77-L83

```csharp
foreach (var set in allAssembliesPerArch)
GenerateTypeMap (set.Key, set.Value.Values.ToList ());
```

Each iteration parses XML typemap files, builds typemap data structures, constructs LLVM IR, and writes `.ll` output -- all independent per ABI. With multi-ABI builds (e.g., `arm64-v8a` + `x86_64`), this work could be parallelized.

The same applies to `GenerateAllTypeMappingsFromNativeState()` which iterates `nativeCodeGenStates` sequentially.

## Proposal

Use `Parallel.ForEach` (or similar) to process each ABI concurrently. The per-arch work (XML parsing, hash computation, LLVM IR generation, file writing) is already isolated by architecture with no shared mutable state between iterations.

Care would be needed for:
- Thread-safe accumulation of `GeneratedBinaryTypeMaps` output items
- The `NativeCodeGenState.TemplateJniAddNativeMethodRegistrationAttributePresent` shared state set after the loop
- Logging (`TaskLoggingHelper` is thread-safe)

## Context

Found while analyzing a binlog where `GenerateTypeMappings` took ~1033ms. Parallelizing across ABIs could cut wall-clock time roughly in half for dual-ABI builds.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.