Skip to content

Add experimental ILLink task caching and cache maintenance - #135065

Open
sbomer wants to merge 5 commits into
mainfrom
sbomer/illink-task-cache
Open

sbomer wants to merge 5 commits into
mainfrom
sbomer/illink-task-cache

Conversation

@sbomer

@sbomer sbomer commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Add experimental whole-invocation caching to the ILLink MSBuild task, enabled through ILLINK_EXPERIMENTAL_CACHE with an optional ILLINK_EXPERIMENTAL_CACHE_PATH override. Reuse successful outputs without running the linker again, with a key covering arguments, paths, input contents, and the task, linker, and host binaries.

Keep this initial implementation narrow: extra arguments bypass caching, cache hits do not replay diagnostics, and the on-disk format has no compatibility guarantee. Include a standalone maintenance tool that purges entries last used before an explicit UTC cutoff. There is no automatic eviction during linking, and purge must run only while the cache is idle. Runtime build integration and CI enablement follow separately.

This content was created with assistance from AI.

Note that this approach is directly inspired by dotnet/roslyn#82881.

@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Oct 1, 2026
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Oct 1, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

sbomer and others added 4 commits October 5, 2026 14:35
Cache eligible whole-task invocations with environment-only opt-in and explicit timestamp-based purging. Bypass caching for extra arguments; runtime-specific argument support is deferred to the next layer.

Assisted-by: Copilot:gpt-6-astra
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 561d1c87-e14b-46f8-be7f-a08f544ec537
Assisted-by: Copilot:gpt-6-astra
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 561d1c87-e14b-46f8-be7f-a08f544ec537
Assisted-by: Copilot:gpt-6-astra
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 561d1c87-e14b-46f8-be7f-a08f544ec537
Replace the write-to-temp + File.Replace + retry approach with a plain
overwrite. File.Replace's ReplaceFile API isn't meant for concurrent
writers to the same destination, which caused a transient Windows CI
failure. A plain File.WriteAllText is safe here: FileShare.Read makes
the OS serialize conflicting writers, so a losing writer's open fails
before touching the file. The marker is advisory bookkeeping, and
CachePurge.cs already tolerates malformed content per entry.

Assisted-by: Claude:claude-sonnet-5 (GitHub Copilot CLI)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 561d1c87-e14b-46f8-be7f-a08f544ec537

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.

Copilot review overview

🟡 Changes recommended

Non-atomic usage-marker refreshes can corrupt timestamps and prevent purge from reclaiming affected entries.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds opt-in caching of complete ILLink MSBuild outputs and a standalone tool for idle-cache maintenance.

Changes:

  • Adds content-based cache keys, output restoration, and successful-result storage.
  • Tracks usage and purges entries older than an explicit UTC cutoff.
  • Adds tests, build integration, and configuration documentation.

Validation was limited to source inspection; builds, tests, and benchmarks were not run.

File Description
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​Mock.cs Exposes cache helpers and captures messages.
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​ILLink.Tasks.Tests.csproj Adds isolated-process testing support.
src/​tools/​illink/​test/​ILLink.Tasks.Tests/​ILLink.Tasks.Tests.cs Tests cache behavior and invalidation.
src/​tools/​illink/​test/​ILLink.CacheTool.Tests/​ILLink.CacheTool.Tests.csproj Adds maintenance test project.
src/​tools/​illink/​test/​ILLink.CacheTool.Tests/​CachePurgeTests.cs Tests purge rules and command validation.
src/​tools/​illink/​src/​ILLink.Tasks/​LinkTask.cs Integrates caching into task execution.
src/​tools/​illink/​src/​ILLink.Tasks/​ILLinkCacheEntry.cs Defines entry names and usage markers.
src/​tools/​illink/​src/​ILLink.Tasks/​ILLinkCache.cs Implements cache storage and restoration.
src/​tools/​illink/​src/​ILLink.Tasks/​ILLink.Tasks.csproj Grants test access to internals.
src/​tools/​illink/​src/​ILLink.CacheTool/​README.md Documents maintenance and installation.
src/​tools/​illink/​src/​ILLink.CacheTool/​Program.cs Defines the purge command.
src/​tools/​illink/​src/​ILLink.CacheTool/​ILLink.CacheTool.csproj Packages the maintenance tool.
src/​tools/​illink/​src/​ILLink.CacheTool/​CachePurge.cs Deletes entries by last-used timestamp.
src/​tools/​illink/​illink.slnx Includes maintenance projects.
eng/​Subsets.props Integrates tool and test builds.
docs/​tools/​illink/​README.md Links cache design documentation.
docs/​tools/​illink/​illink-tasks.md Documents configuration and maintenance.
docs/​design/​tools/​illink/​task-cache.md Specifies cache behavior and limitations.

Comment thread src/tools/illink/src/ILLink.Tasks/ILLinkCacheEntry.cs
Keep purge usable if a best-effort last-used refresh leaves an invalid marker. Report the fallback while preserving errors for actual maintenance failures.

Assisted-by: GitHub Copilot CLI:gpt-6-sol

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 561d1c87-e14b-46f8-be7f-a08f544ec537

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

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants