Skip to content

[assembly-preparer] Don't run the preserve/optimize/mark steps when not trimming.#26014

Open
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/assembly-preparer-skip-some-when-untrimmed
Open

[assembly-preparer] Don't run the preserve/optimize/mark steps when not trimming.#26014
rolfbjarne wants to merge 1 commit into
mainfrom
dev/rolf/assembly-preparer-skip-some-when-untrimmed

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

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

🤖 Pull request created by Copilot

…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>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as ready for review July 10, 2026 09:50
Copilot AI review requested due to automatic review settings July 10, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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, and Mark* steps on configuration.Application.AreAnyAssembliesTrimmed.
  • Always add InlineDlfcnMethodsStep after the conditional block to preserve previous ordering when trimming is enabled.

Comment thread tools/assembly-preparer/AssemblyPreparer.cs
Comment thread tools/assembly-preparer/AssemblyPreparer.cs
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: c805121a6019f7aa7f6c022b1932b6eea0c05eb1 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [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
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 17 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 18 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: c805121a6019f7aa7f6c022b1932b6eea0c05eb1 [PR build]

@rolfbjarne rolfbjarne enabled auto-merge (squash) July 10, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants