Skip to content

[build] Make local no-op SDK builds incremental - #13774

Draft
simonrozsival wants to merge 5 commits into
simonrozsival-build-entry-pointsfrom
simonrozsival-local-build-baseline
Draft

simonrozsival wants to merge 5 commits into
simonrozsival-build-entry-pointsfrom
simonrozsival-local-build-baseline

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Stacked on #13430. Context: dotnet/sourcelink#1290, dotnet/roslyn#86006.

With the dotnet build Microsoft.Android.slnx entry point, a build with no source changes still took ~19 s locally, and every C# or Java edit paid that cost before doing useful work. Incorrect inputs and outputs, unconditional file writes, and local workload work contributed to repeated builds:

  • Preserve WorkloadManifest.json/.targets timestamps when their contents have not changed, so they no longer invalidate workload installation on every build.
  • Skip WorkloadDependencies.proj for the local workload; packing the shipped manifest still generates data/WorkloadDependencies.json.
  • Correct the Bytecode tests' module-info.class output, exclude the templates project's bin/ and obj/ from template inputs, and touch the copied java-source-utils.jar so these targets can become up to date.
  • Give BuildExtraApiLevels file-based inputs and a stamp output, with state for relevant input settings and generated files. Missing files and changed API-specific profiles still trigger recovery; lists and asset caches produced by later workload setup are excluded.
  • Generate native runtime lists only for the latest stable API, where their packs exist. Track managed lists per API and copy the analyzer into extra-API reference packs, repairing it if deleted or updated.
  • Resolve workload packs each time, preserve an unchanged dependency project's timestamp, and combine restore and install in one MSBuild process. Record extracted entries in the existing install marker to repair missing files and obsolete or malformed markers.

Worktree revision accuracy

SourceLink 8 could report Repository has no commit in a Git worktree when the branch ref was packed in Git's common directory. A succeeding build could lose SourceRevisionId, changing AssemblyInformationalVersion and causing solution-wide recompilation without any source edit. Upgrade Microsoft.SourceLink.GitHub to 10.0.301, which resolves the packed-ref fixture correctly. Exclude its transitive compile and runtime assets so its System.IO.Hashing 10.0.10 dependency does not conflict with the repository's direct 12.0 dependency; its build tasks retain their own required assemblies.

Performance

Apple M5 Max (18 cores, 64 GB), macOS 26.7.3, .NET SDK 12.0.100-alpha.1.26551.101 via dotnetup.

Earlier full-build comparison

Each scenario ran dotnetup dotnet build Microsoft.Android.slnx -c Debug -m:4 -nr:false in two worktrees: before = #13430 head d0aa1bfd5a, after = this branch at a9806c076d, before the extra-API and later changes. Runs were sequential and interleaved before/after. The shared host's one-minute load ranged from 5 to 25; differences below ~10% for builds longer than a minute are within noise. “Edit” appends a comment; “revert” restores it and is itself a source change.

Scenario Before After Δ
Clean (git clean -xdf) 270.2 s 232.8 s inconclusive¹
Second build after clean 139.9 s 131.4 s inconclusive¹
No-op (median of 4) 19.1 s (18.3–22.3) 16.1 s (15.8–17.5) −3.0 s (−16%)
Xamarin.Android.Build.Tasks edit (MonoAndroidHelper.cs) 18.9 s 15.8 s −3.1 s
…revert 18.5 s 16.5 s −2.0 s
Java runtime edit (MonoPackageManager.java) 19.2 s 17.4 s −1.8 s
…revert 19.4 s 16.4 s −3.0 s
Native edit (src/native/clr/host/host.cc) 58.1 s 54.3 s −3.8 s
…revert 61.3 s 54.6 s −6.7 s
Mono.Android edit (JNIEnv.cs) 90.3 s 121.1 s inconclusive²
…revert 100.9 s 100.8 s ±0

¹ Single clean runs at load ~14 do not establish a reliable difference. The second build still costs ~135 s because the first does not converge; that is a separate issue. ² Load rose from 14 to 25 during the after-edit run; single samples do not establish the cause. Compiling Mono.Android.dll and dependent packs remains expensive.

Runtime lists and workload installation

Three interleaved targeted CreateLocalRuntimeLists runs took 33.45, 32.21 and 33.35 seconds before (median 33.35 s) and 14.84, 14.82 and 14.65 seconds after limiting native lists to existing packs (median 14.82 s). Child builds fell from 21 to nine. These precede the managed-list invalidation fix and are not full-solution timings.

Three interleaved full-solution no-op pairs compared separate workload restore and install processes with the combined process: medians 16.03 s (15.98–16.26) and 14.45 s (14.18–16.21), respectively; InstallWorkloadPacks target medians were 2.998 and 1.703 seconds. Host load fell from ~40 to 18, confounding the wall-time comparison. Pack resolution and the combined restore/install process still run on no-op builds, but extraction/copy targets skip when current.

Later full-build samples

The same Debug solution command, with warm caches, gave these unpaired samples; they are not a controlled comparison with the earlier revisions:

Scenario Wall time
No-op after e1583cf69f (three runs) 12.66, 11.86, 12.74 s (median 12.66 s)
JNIEnv.cs edit / revert after e1583cf69f 87.27 / 89.68 s
No-op before e1583cf69f (three runs) 14.50, 18.01, 19.86 s (median 18.01 s)
Build.Tasks C# edit / revert before e1583cf69f 17.30 / 16.06 s
Native C++ edit / revert before e1583cf69f 24.69 / 42.15 s
JNIEnv.cs edit before e1583cf69f 396.07 s
Release build, initially absent bin/Release 230.84 s
No-op with SourceLink 10.0.301 before final commit (three runs) 12.50, 12.39, 13.17 s (median 12.50 s)
No-op at final 691e8c6582 (three runs) 32.97, 40.08, 23.51 s (median 32.97 s)

Binding edits/reverts rebuilt all three API-level assemblies. The e1583cf69f no-ops started at load 6–7 and its edit/revert at load 9–15. Load rose from ~26 to over 80 during the pre-commit binding edit, so 396.07 s is not a reliable comparison; the matching revert succeeded but the computer slept for 12,399 s. Native edit/revert each ran six native compilation commands. The Release run used warm caches and potentially existing intermediates; it is not a clean comparison.

After the SourceLink commit changed HEAD, the first Debug solution build took 317.80 s and made 128 Csc calls after the revision changed. The following three no-ops invoked no Csc tasks. Load rose from ~34 to 65 during the first build and was ~51–65 during the no-ops, so those timings are not comparable to the quieter earlier runs. C# and C++ edits were not remeasured at final HEAD under this load. The pre-commit 12.50 s median is unpaired and does not establish an ordinary no-op speedup from SourceLink.

The SourceLink failure was a pathological transition rather than a normal no-op baseline: a 100.08 s build was followed without source changes by a 147.30 s build with 128 Csc calls, then 19.78 and 12.51 s builds. The slow follow-up changed the assembly informational version from 1.0.0+<HEAD> to 1.0.0.

Per-target times from earlier no-op binlogs:

Target Before After
_GenerateXAWorkloadContent 1651 ms 14 ms
InstallManifestAndDependencies 6690 ms 4696 ms
BuildClasses + BuildJar 655 ms 0 ms
BuildExtraApiLevels ~2200 ms 4 ms (skipped; input discovery 7 ms, after 6cc11e7e5f)

The sub-second no-op and sub-minute binding-edit goals remain unmet. Prepare still starts three child builds (~4.7 s in the earlier no-op), workload setup and full solution traversal remain, and the binding edit rebuilds three API-level assemblies. The binding-edit binlog recorded three compiler calls totalling 60.9 s and 41.2 s inside BuildExtraApiLevels; these inclusive totals overlap and are not additive wall times.

Isolated compiler-cache prototype (not shipped)

An owned compiler trace showed contention in Roslyn's control-flow-graph cache, also reported in dotnet/roslyn#86006. In a session-owned copy of the pinned SDK compiler, a diagnostic prototype replaced that cache's ConcurrentDictionary.Count > 0 check with !IsEmpty. The installed SDK was not modified and the prototype is not part of this change.

Eight interleaved standalone Mono.Android.csproj Debug builds used -m:1 -nr:false -p:UseSharedCompilation=false, identical compiler arguments and enabled analyzers, touching the unchanged JNIEnv.cs before each to force compilation. Stock builds took 110.62, 93.37, 88.00, 66.26 s (median 90.69 s); prototype builds took 76.91, 62.08, 68.06, 59.47 s (median 65.07 s). Median Csc task time was 68.09 → 51.53 s. Reference/implementation DLL, PDB and diagnostic-text hashes matched in all eight runs. The shared host's one-minute load varied from approximately 33 to 68; these are not full-solution timings and are not controlled enough to claim a precise general speedup. They support investigating the upstream fix, not shipping a patched compiler.

Experiments not retained

  • Parallel extra-API builds: serial full-solution C# runs 92.79/81.71/78.14 s versus safe parallel runs 94.07/88.34/80.05 s. The naive version raced on shared outputs; the safer version was slower.
  • A framework-list shortcut removed about 5.2 s of generator work for PDB-only changes, but removing Configuration.Override.props could leave stale metadata. It was reverted. Before C# samples were 126.55/111.10/112.13 s and candidate samples 89.43/81.79/83.68 s, but the overall difference is confounded by host load and compilation variation.
  • Required analyzers stayed enabled. Serial compilation measured 67.11/65.72/74.57 s versus default 45.24/50.34/61.19 s; a per-compiler processor cap showed only a noisy difference, so neither was retained.
  • Parallel Prepare runs (6.42/6.16/5.39 s versus 5.86/5.37/5.35 s) and workload-tool --no-restore/static-graph variants showed no reliable gain.

Validation

  • All 28 earlier matched benchmark builds succeeded; binlogs confirmed that edits recompiled the affected C#, Java, or native inputs and no-op targets skipped.
  • dotnetup dotnet pack build-tools/create-packs/Microsoft.NET.Sdk.Android.proj -c Debug -o /tmp/mpack: passed; the manifest package contains WorkloadDependencies.json, WorkloadManifest.json and WorkloadManifest.targets.
  • ./dotnet-local.sh new android -o /tmp/benchapp/App1 && ./dotnet-local.sh build /tmp/benchapp/App1 -c Debug: passed and produced a signed APK. Changing and reverting a template and WorkloadManifest.in.json repacked the templates and updated/restored the installed manifest.
  • dotnetup dotnet build Microsoft.Android.slnx -c Debug -m:4 -nr:false -v:diag: two no-op runs passed in 16.86/17.16 s with zero warnings/errors and skipped BuildExtraApiLevels. Touching the 37.1 profile reran it (four RS0025 warnings, no errors); deleting a generated 37.1 Java.Interop.dll restored it, and the following no-op skipped the target.
  • Earlier Debug and Release solution builds passed after the runtime-list change (132 and 257 warnings, respectively, including SourceLink/binding warnings). At e1583cf69f, three no-ops passed without warnings; JNIEnv.cs edit/revert builds each passed with 10 warnings and rebuilt all three API assemblies.
  • dotnetup dotnet build build-tools/workload-tools/workload-tools.csproj -c Debug -m:4 -nr:false and dotnetup dotnet build build-tools/create-packs/Microsoft.Android.Sdk.proj -c Debug -m:4 -nr:false -t:InstallManifestAndDependencies: passed; generated dependency-project content and timestamp stayed unchanged.
  • The same SDK project with -t:CreateLocalRuntimeLists passed no-op, per-API managed-input change, missing managed/native-list recovery, and a subsequent no-op; all nine lists matched their previous contents and were registered in FileWrites. With -t:CreateLocalFrameworkLists, a deleted 37.1 analyzer was restored byte-for-byte and the next invocation skipped copying.
  • ./dotnet-local.sh build "$app" -c Debug -p:TargetPlatformVersion=<37.0|37.1|37.2>: all three API-level CoreCLR smoke builds passed. Release API 37.1 and optimized Debug NativeAOT/arm64 smoke builds also produced signed APKs; the NativeAOT build reported _AndroidRuntime=NativeAOT and included the native app library.
  • Isolated Debug and Release workload-install fixtures verified changed roots and package membership, missing extracted and packed files, legacy/malformed markers, and retry after failed extraction. Inventories check existence, not hashes; existing SDK-root packs remain trusted.
  • An isolated packed-ref Git worktree fixture reproduced SourceLink 8.0.0 and 10.0.300 failing to resolve HEAD; 10.0.301 resolved it and emitted the correct SourceLink mapping. Direct hashing references retained version 12.0, while projects with only SourceLink had compile/runtime placeholders.
  • dotnetup dotnet build Microsoft.Android.slnx -c Debug -m:4 -nr:false -clp:PerformanceSummary "-bl:$logdir/sourcelink-final-head-full.binlog" at 691e8c6582: passed, as did three subsequent no-ops; the no-ops invoked no C# compiler and SourceLink mapped the current HEAD. dotnetup dotnet build Microsoft.Android.slnx -c Release -m:4 -nr:false -warnaserror:MSB3277 "-bl:$logdir/sourcelink-fixed-release-full.binlog" passed before the final commit, as did targeted NativeAOT and Android SDK builds with the same warning-as-error setting.
  • dotnetup dotnet test tests/Microsoft.Android.Build.BaseTasks-Tests/Microsoft.Android.Build.BaseTasks-Tests.csproj -c Debug -m:4 -nr:false "-bl:$logdir/sourcelink-final-basetasks-tests.binlog": 167 passed, 4 skipped at final HEAD.
  • dotnetup dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -c Debug -p:AndroidToolsDisableMultiTargeting=false -p:DotNetTargetFrameworkVersion=10.0 --no-build --environment "HOME=$testhome": 450 passed, 7 skipped with $testhome set to an isolated directory. The first attempt encountered an unrelated host JDK discovery conflict.

simonrozsival and others added 2 commits November 25, 2026 12:55
Give BuildExtraApiLevels real file inputs and track its output set so no-op solution builds can skip extra API-level builds while detecting changed profiles, changed settings, and missing pack outputs.

Co-authored-by: Copilot App <[email protected]>
Generate native runtime lists only for the existing API-level packs and track managed lists independently. Restore missing extra-API analyzers and incomplete workload packs, and combine workload restore and installation.

Co-authored-by: Copilot App <[email protected]>
Upgrade SourceLink so worktrees whose branch refs are packed retain the correct revision and do not trigger a solution-wide rebuild when source metadata changes. Exclude its compile and runtime assets to avoid conflicting with the System.IO.Hashing version used by Android build tasks.

Co-authored-by: Copilot App <[email protected]>

This branch has not been deployed

No deployments
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