Skip to content

Increase Helix work item chunk size for NetAnalyzer tests#53930

Closed
MichaelSimons wants to merge 7 commits intodotnet:mainfrom
MichaelSimons:sdk-helix-tuning
Closed

Increase Helix work item chunk size for NetAnalyzer tests#53930
MichaelSimons wants to merge 7 commits intodotnet:mainfrom
MichaelSimons:sdk-helix-tuning

Conversation

@MichaelSimons
Copy link
Copy Markdown
Member

@MichaelSimons MichaelSimons commented Apr 16, 2026

Summary

Introduces config-driven Helix work item scheduling to reduce CI wall-clock time by:

  1. Consolidating oversharded assemblies — per-assembly MethodLimitMultiplier in a checked-in XML config
  2. Longest-first (LPT) ordering — work items sorted by estimated duration descending so heavy items get dispatched first

Problem

Analysis of build 1382230 (TestBuild: linux x64) showed:

  • 475 total work items on 39 machines, ~40 min wall-clock despite longest item being ~17 min
  • 197 NetAnalyzer items (41%) averaged just 40 seconds — massive scheduling overhead
  • Machine a00FR27 got 3 heavy items stacked (30 min total) while others had <5 min — load imbalance from FIFO dispatch
  • Several other assemblies (TemplateEngine.Cli, Build.Tasks, ApiDiff, etc.) were also oversharded into 8-11 tiny items

Changes

HelixSchedulingConfig.xml (new, embedded resource)

Per-assembly configuration with two knobs:

  • MethodLimitMultiplier: Controls chunk size. NetAnalyzers 5×, StaticWebAssets 4×, TemplateEngine.Cli 11×, etc.
  • EstimatedSecondsPerMethod: Enables LPT scheduling. Publish.Tests (22s/method) gets dispatched before NetAnalyzers (2.5s/method).

HelixSchedulingConfig.cs (new)

Loads the embedded XML and provides lookup methods for multiplier and estimated duration.

SDKCustomCreateXUnitWorkItemsWithTestExclusion.cs (modified)

  • Uses config-driven method limits instead of hardcoded values
  • After generating all work items, sorts them by estimated duration descending (LPT) before outputting

Expected impact

Metric Before After (estimated)
Total work items ~475 ~260
NetAnalyzer items ~197 ~39
Work item ordering Alphabetical Longest-first
Theoretical wall-clock ~40 min ~25-30 min

How to validate

Compare the TestBuild linux (x64) leg of this PR's CI run against the baseline:

  • Count of Helix work items (should drop ~40%)
  • Wall-clock time of the Run TestBuild Tests step
  • Check that no individual work item exceeds 20 min (no new long-tail)

The NetAnalyzer unit tests were being split into ~197 tiny work items
(avg 40s each) due to the default methodLimit of 16. This creates
excessive per-item overhead in Helix (payload download, setup, results
upload) and consumes machine slots that could serve longer-running tests.

Use a 5x larger methodLimit for NetAnalyzer assemblies, reducing the
~197 items to ~39 items averaging ~3-4 minutes each. This better
matches the available machine count and amortizes per-item overhead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 22:03
@MichaelSimons MichaelSimons marked this pull request as draft April 16, 2026 22:04
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 adjusts Helix xUnit work item partitioning to reduce Helix overhead caused by excessive fragmentation of the Microsoft.CodeAnalysis.NetAnalyzers.UnitTests.dll test run.

Changes:

  • Introduce a methodLimit variable for AssemblyScheduler instead of inlining the conditional.
  • Detect NetAnalyzers test assemblies and increase the AssemblyScheduler methodLimit by 5x to produce fewer, larger work items.

}

var scheduler = new AssemblyScheduler(methodLimit: !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TestFullMSBuild")) ? 32 : 16);
int methodLimit = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TestFullMSBuild")) ? 32 : 16;
MichaelSimons and others added 2 commits April 16, 2026 22:32
Introduce HelixSchedulingConfig.xml (embedded resource) that specifies
per-assembly MethodLimitMultiplier and EstimatedSecondsPerMethod.

- MethodLimitMultiplier controls chunk size: oversharded assemblies
  (NetAnalyzers 5x, StaticWebAssets 4x, TemplateEngine.Cli 11x, etc.)
  get consolidated into fewer, larger work items.
- EstimatedSecondsPerMethod enables longest-first (LPT) scheduling:
  after all work items are created, they are sorted by estimated
  duration descending so Helix machines pick up heavy items first.
  This reduces the chance of long items stacking on the same machine.

Based on analysis of build 1382230 (TestBuild: linux x64) where 475
work items ran on 39 machines with 40min wall-clock despite a 17min
longest item — caused by machine load imbalance and 197 tiny
NetAnalyzer items consuming scheduling overhead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Skip RunFileTests_CscOnlyAndApi.CscOnly to eliminate retry amplification
and get a clean measurement of Helix scheduling optimizations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants