[assembly-preparer] Don't run the preserve/optimize/mark steps when not trimming.#26014
[assembly-preparer] Don't run the preserve/optimize/mark steps when not trimming.#26014rolfbjarne wants to merge 1 commit into
Conversation
…ot trimming. PreserveProtocolsStep, PreserveSmartEnumConversionsStep, PreserveBlockCodeStep, OptimizeGeneratedCodeStep, ApplyPreserveAttributeStep, MarkForStaticRegistrarStep and MarkNSObjectsStep only do work for assemblies that are being trimmed (their IsActiveFor requires the assembly's action to be AssemblyAction.Link). When nothing is being trimmed no assembly has that action, so these steps are no-ops that just iterate every assembly checking IsActiveFor. Don't add them to the step list at all in that case (gated on AreAnyAssembliesTrimmed), which matches how the ILLink path guards the same steps (on _AreAnyAssembliesTrimmed in Xamarin.Shared.Sdk.targets). Verified with monotouch-test on iOS (3675 tests, 0 failed) both with trimming (release|linksdk - the steps still run) and without (link None - the steps are skipped). Before build times: | Project | Runtime identifier | Link mode | PrepareAssemblies=false | PrepareAssemblies=true | Difference | | -------------- | ------------------ | --------- | ----------------------- | ---------------------- | ------------ | | monotouch-test | ios-arm64 | None | 00:02:12.42 | 00:02:17.27 | 00:00:04.84 | | monotouch-test | ios-arm64 | SdkOnly | 00:01:29.23 | 00:01:52.19 | 00:00:22.95 | | monotouch-test | iossimulator-arm64 | None | 00:01:44.58 | 00:01:47.33 | 00:00:02.74 | | monotouch-test | iossimulator-arm64 | SdkOnly | 00:01:16.03 | 00:01:27.52 | 00:00:11.49 | | MySimpleApp | ios-arm64 | None | 00:01:16.71 | 00:01:18.90 | 00:00:02.19 | | MySimpleApp | ios-arm64 | SdkOnly | 00:00:20.77 | 00:00:44.71 | 00:00:23.94 | | MySimpleApp | iossimulator-arm64 | None | 00:00:52.84 | 00:00:56.09 | 00:00:03.25 | | MySimpleApp | iossimulator-arm64 | SdkOnly | 00:00:19.74 | 00:00:28.54 | 00:00:08.80 | After build times: | Project | Runtime identifier | Link mode | PrepareAssemblies=false | PrepareAssemblies=true | Difference | | -------------- | ------------------ | --------- | ----------------------- | ---------------------- | ------------ | | monotouch-test | ios-arm64 | None | 00:02:18.08 | 00:02:22.85 | 00:00:04.76 | | monotouch-test | ios-arm64 | SdkOnly | 00:01:34.83 | 00:01:55.70 | 00:00:20.87 | | monotouch-test | iossimulator-arm64 | None | 00:01:52.98 | 00:01:49.63 | -00:00:03.34 | | monotouch-test | iossimulator-arm64 | SdkOnly | 00:01:21.16 | 00:01:24.04 | 00:00:02.87 | | MySimpleApp | ios-arm64 | None | 00:01:15.93 | 00:01:22.34 | 00:00:06.41 | | MySimpleApp | ios-arm64 | SdkOnly | 00:00:21.54 | 00:00:44.93 | 00:00:23.39 | | MySimpleApp | iossimulator-arm64 | None | 00:00:57.90 | 00:00:57.86 | -00:00:00.04 | | MySimpleApp | iossimulator-arm64 | SdkOnly | 00:00:21.41 | 00:00:27.36 | 00:00:05.95 | Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR optimizes the assembly-preparer pipeline by avoiding adding linker-only preservation/optimization/marking steps when no assemblies are being trimmed, reducing unnecessary per-assembly IsActiveFor checks in non-trimming builds.
Changes:
- Gate adding
Preserve*,OptimizeGeneratedCodeStep,ApplyPreserveAttributeStep, andMark*steps onconfiguration.Application.AreAnyAssembliesTrimmed. - Always add
InlineDlfcnMethodsStepafter the conditional block to preserve previous ordering when trimming is enabled.
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
🚀 [CI Build #c805121] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 199 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
PreserveProtocolsStep, PreserveSmartEnumConversionsStep, PreserveBlockCodeStep,
OptimizeGeneratedCodeStep, ApplyPreserveAttributeStep, MarkForStaticRegistrarStep
and MarkNSObjectsStep only do work for assemblies that are being trimmed (their
IsActiveFor requires the assembly's action to be AssemblyAction.Link). When
nothing is being trimmed no assembly has that action, so these steps are no-ops
that just iterate every assembly checking IsActiveFor. Don't add them to the step
list at all in that case (gated on AreAnyAssembliesTrimmed), which matches how the
ILLink path guards the same steps (on _AreAnyAssembliesTrimmed in
Xamarin.Shared.Sdk.targets).
Verified with monotouch-test on iOS (3675 tests, 0 failed) both with trimming
(release|linksdk - the steps still run) and without (link None - the steps are
skipped).
Before build times:
After build times:
🤖 Pull request created by Copilot