Skip to content

Consolidate Helix shards for quick test assemblies via MethodLimitMultiplier#54115

Merged
MichaelSimons merged 6 commits into
dotnet:mainfrom
MichaelSimons:consolidate-helix-shards
May 6, 2026
Merged

Consolidate Helix shards for quick test assemblies via MethodLimitMultiplier#54115
MichaelSimons merged 6 commits into
dotnet:mainfrom
MichaelSimons:consolidate-helix-shards

Conversation

@MichaelSimons
Copy link
Copy Markdown
Member

@MichaelSimons MichaelSimons commented Apr 27, 2026

Summary

Adds a MethodLimitMultiplier metadata option for SDKCustomXUnitProject items to consolidate Helix test shards for assemblies that produce many very short work items. This reduces per-item overhead (payload download, agent allocation, setup, teardown) and makes us better citizens of the shared Helix queues.

How it works

AssemblyScheduler partitions each test assembly into shards based on a methodLimit threshold (default 16, or 32 for FullFramework). MethodLimitMultiplier simply multiplies that threshold, producing fewer, larger shards. It is set via MSBuild item metadata in UnitTests.proj — no new config files.

Changes

  • SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs — Reads optional MethodLimitMultiplier metadata; warns on invalid values
  • UnitTests.proj — Applies multipliers to three assembly groups:
    • NetAnalyzers (x5)
    • TemplateEngine / TemplateSearch (x20)
    • Api — ApiCompatibility, ApiDiff, ApiSymbolExtensions, GenAPI (x10)

Results

Comparison of latest PR validation run (build 1407886) against main (build 1405738).

Linux x64

Group Main Shards (Avg) PR Shards (Avg / Max) Saved
NetAnalyzers 197 (0m41s) 70 (1m09s / 3m21s) 127
TemplateEngine¹ 50 (0m19s) 15 (0m33s / 1m23s) 35
Api¹ 23 (0m17s) 5 (0m43s / 1m02s) 18
Total 515 335 180

Windows x64

Group Main Shards (Avg) PR Shards (Avg / Max) Saved
NetAnalyzers 197 (1m27s) 70 (2m36s / 4m57s) 127
TemplateEngine¹ 50 (0m45s) 15 (1m12s / 2m33s) 35
Api¹ 23 (0m48s) 5 (2m28s / 2m42s) 18
Total 518 338 180

macOS x64

Group Main Shards (Avg) PR Shards (Avg / Max) Saved
NetAnalyzers 197 (1m09s) 70 (1m28s / 3m02s) 127
TemplateEngine¹ 50 (0m42s) 15 (0m52s / 1m28s) 35
Api¹ 23 (0m36s) 5 (1m06s / 2m01s) 18
Total 515 335 180

FullFramework Windows

Group Main Shards (Avg) PR Shards (Avg / Max) Saved
NetAnalyzers 129 (2m04s) 40 (3m50s / 5m03s) 89
TemplateEngine¹ 33 (0m50s) 15 (2m15s / 2m46s) 18
Api¹ 21 (1m21s) 9 (2m17s / 4m20s) 12
Total 348 229 119

Overall

Leg Main Shards PR Shards Saved
Linux x64 515 335 180
Windows x64 518 338 180
macOS x64 515 335 180
FullFx Windows 348 229 119
Total 1896 1237 659

Each eliminated work item avoids the fixed per-item overhead of agent allocation, payload download, environment setup, and teardown. While this overhead is non-trivial, it varies by queue and machine and is difficult to measure precisely from a single comparison.

¹ TemplateEngine and Api assemblies are now at one shard per assembly — the minimum possible without cross-assembly consolidation. Further shard reduction for these groups would require changes to the Helix sharding model itself.

MichaelSimons and others added 2 commits April 27, 2026 20:27
…tiplier

Add per-assembly MethodLimitMultiplier metadata support to reduce wasted
Helix compute on assemblies whose shards all complete very quickly. The
multiplier increases the methods-per-shard threshold, producing fewer but
larger work items and reducing per-item setup overhead.

Applied to three assembly groups:
- Microsoft.CodeAnalysis.NetAnalyzers (x5)
- Microsoft.TemplateEngine.* / TemplateSearch.* (x10)
- Microsoft.DotNet.Api{Compatibility,Diff,SymbolExtensions} (x5)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TE assemblies are already single-shard on FullFramework at x10.
The x20 bump collapses the remaining 2-shard assemblies on TestBuild
legs (Cli.UnitTests, Core.UnitTests, Orchestrator) to single shards.

Api group bumped to x10 and expanded to include GenAPI.Tests and
PackageValidation.Tests for additional shard savings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MichaelSimons MichaelSimons force-pushed the consolidate-helix-shards branch from bbc8430 to db5ebf7 Compare April 28, 2026 13:13
@MichaelSimons MichaelSimons marked this pull request as ready for review May 4, 2026 19:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds a per-assembly Helix sharding knob for test projects so selected fast-running assemblies can run in fewer, larger work items. In the SDK test infrastructure, this lets UnitTests.proj tune shard density through item metadata instead of hard-coding assembly-specific behavior deeper in the task implementation.

Changes:

  • Adds MethodLimitMultiplier handling to SDKCustomCreateXUnitWorkItemsWithTestExclusion and uses it to scale the scheduler’s per-shard method limit.
  • Applies multiplier metadata in UnitTests.proj for NetAnalyzers, TemplateEngine/TemplateSearch, and selected API test assemblies.
  • Keeps the existing default shard thresholds intact for assemblies that do not opt into the new metadata.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
test/UnitTests.proj Adds MethodLimitMultiplier metadata to selected SDKCustomXUnitProject items to reduce Helix shard counts for targeted test groups.
test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs Reads the new metadata, validates it, and applies the scaled method limit when partitioning test assemblies into Helix work items.

Comment thread test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs
Comment thread test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs
Comment thread test/HelixTasks/SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs
Update the XML docs on the XUnitProjects property to include the
optional MethodLimitMultiplier metadata, keeping the documented
inputs in sync with the implementation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@MichaelSimons MichaelSimons enabled auto-merge (squash) May 6, 2026 14:41
@MichaelSimons
Copy link
Copy Markdown
Member Author

/ba-g known intermitent failure in netanalyzer tests

@MichaelSimons MichaelSimons merged commit b89460e into dotnet:main May 6, 2026
22 of 24 checks passed
@MichaelSimons MichaelSimons deleted the consolidate-helix-shards branch May 6, 2026 15:52
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.

3 participants