Skip to content

[TrimmableTypeMap] Parallelize JCW source generation #11490

@simonrozsival

Description

@simonrozsival

Part of #10958.

JcwJavaSourceGenerator.GenerateContent(...) currently generates Java Callable Wrapper source content sequentially, even though each Java peer's .java file is independent. PR #10924 measurements in #10958 showed JCW generation as the dominant cold-build phase, so this is a good contained optimization candidate.

Current locations

  • src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs
    • GenerateContent(...) loops over all peers serially.
  • src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs
    • GenerateJcwJavaSources(...) calls GenerateContent(...) after filtering peers.
  • src/Xamarin.Android.Build.Tasks/Tasks/GenerateTrimmableTypeMap.cs
    • WriteJavaSourcesToDisk(...) writes the generated source list using Files.CopyIfStreamChanged(...).

Suggested implementation

  • Generate source content in parallel across peers.
  • Preserve deterministic output ordering so task outputs and tests remain stable.
  • Avoid sharing mutable TextWriter/generator state across workers unless it is proven thread-safe; the simplest approach is one local StringWriter per peer.
  • Keep the existing content-comparison write behavior.

Acceptance criteria

  • JCW source generation uses parallelism for independent peers.
  • Generated file paths/content remain deterministic and behavior-compatible with existing tests.
  • Existing trimmable typemap tests pass; add a focused test if ordering or thread-safety needs coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilot`copilot-cli` or other AIs were used to author thistrimmable-type-map

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions