Average multi microbenchmarks results#5215
Conversation
…ks when creating suites
There was a problem hiding this comment.
Pull request overview
This PR updates the GC microbenchmark infrastructure to support aggregating (averaging) results across multiple microbenchmark runs/iterations, while also renaming/refactoring parts of the analysis/presentation pipeline and introducing an outlier-removal helper.
Changes:
- Add configurable microbenchmark iteration count (
iterations) and wire it into suite creation and execution. - Replace the previous single-result comparison flow with a new per-benchmark aggregation/comparison pipeline (
MicrobenchmarkResultComparison,GCTraceMetrics,GCTraceMetricComparisonResult). - Refactor output generation to primarily emit JSON (markdown generation currently disabled).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure/Commands/RunCommand/CreateSuiteCommand.cs | Reads configured iteration count and applies it to microbenchmark suite environment. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure/Commands/RunCommand/BaseSuite/MicrobenchmarksToRun.txt | Updates baseline suite benchmark list. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure/Commands/RunCommand/BaseSuite/Microbenchmarks.yaml | Renames environment iteration setting to iterations. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure/Commands/Microbenchmark/MicrobenchmarkCommand.cs | Runs microbenchmarks for iterations and switches to new aggregation/comparison logic before presenting results. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure/Commands/Microbenchmark/MicrobenchmarkAnalyzeCommand.cs | Updates analysis-only command to use the new aggregation/comparison logic. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Presentation.cs | Changes presentation API to accept precomputed grouped results; markdown output path currently disabled. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Markdown.cs | Markdown generation code is commented out. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Json/JsonOutput.cs | Removes unused placeholder type. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Json.cs | Moves JSON generator to Microbenchmarks presentation namespace and updates signature for grouped results. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/Microbenchmarks.Configuration.cs | Renames iteration to iterations in microbenchmark environment configuration. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Configurations/InputConfiguration.cs | Adds iterations map to input configuration. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/Microbenchmarks/MicrobenchmarkResultsAnalyzer.cs | Removes old analyzer/comparison pipeline. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/Microbenchmarks/MicrobenchmarkResultComparison.cs | Adds new JSON/trace mapping, per-benchmark analysis, and aggregation/grouping logic. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/Microbenchmarks/MicrobenchmarkResult.cs | Introduces new MicrobenchmarkResult model (namespace currently mismatched vs usage). |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/Microbenchmarks/MicrobenchmarkComparisonResult.cs | Updates comparison to support averaged values/outlier removal and new trace-metric comparisons. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/GCTraceMetrics.cs | Adds trace-derived metric extraction (includes reflection/stat bugs). |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/GCTraceMetricComparisonResult.cs | Adds averaged comparison for trace metrics (baseline vs comparand). |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/GCTraceMetricComparison.cs | Adds helper wrapper for metric comparison construction. |
| src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Analysis/BdnJsonResult.cs | Refactors BDN JSON model types; renames top-level to BdnJsonResult. |
| src/benchmarks/gc/GC.Infrastructure/GC.Analysis.API/Statistics.cs | Adds RemoveOutliers helper (IQR method). |
| src/benchmarks/gc/GC.Infrastructure/Configurations/Run.yaml | Adds iteration configuration block (currently mismatched with new iterations input model). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…chmarks namespace
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…om/VincentBu/performance into average-microbenchmarks-iterations
Redesign microbenchmark result
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 11 comments.
Comments suppressed due to low confidence (1)
src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Markdown.cs:175
AveragedBaselineOtherMetrics/AveragedComparandOtherMetricsareDictionary<string,double>, soGetValueOrDefault(column)returns0when the metric is missing. That makes missing metrics look like real 0 values and can produce incorrect deltas (and divide-by-zero indeltaPercent). UseTryGetValueand only compute delta/delta% when both sides have a value and the baseline is non-zero.
foreach (var column in configuration.Output.Columns)
{
double? baselineValue = lr.AveragedBaselineOtherMetrics.GetValueOrDefault(column);
double? comparandValue = lr.AveragedComparandOtherMetrics.GetValueOrDefault(column);
string baselineResult = baselineValue.HasValue ? Math.Round(baselineValue.Value, 4).ToString() : string.Empty;
string comparandResult = comparandValue.HasValue ? Math.Round(comparandValue.Value, 4).ToString() : string.Empty;
double? delta = baselineValue.HasValue && comparandValue.HasValue ? comparandValue.Value - baselineValue.Value : null;
string deltaResult = delta.HasValue ? Math.Round(delta.Value, 4).ToString() : string.Empty;
double? deltaPercent = delta.HasValue ? (delta / baselineValue.Value) * 100 : null;
string deltaPercentResult = deltaPercent.HasValue ? Math.Round(deltaPercent.Value, 4).ToString() : string.Empty;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated 8 comments.
Comments suppressed due to low confidence (1)
src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/Presentation/Microbenchmarks/Json.cs:15
Json.Generatedoesn’t use theconfigurationparameter, and theusing GC.Analysis.API;/using GC.Infrastructure.Core.Presentation.GCPerfSim;directives are unused. Consider removing the unused parameter/usings to avoid warnings and keep the API surface minimal.
| .ToDictionary(); | ||
|
|
||
| OtherMetrics = OtherMetrics.Concat(customStatistics).ToDictionary(); | ||
|
|
||
| if (gcData != null) | ||
| { | ||
| var customGCData = columns | ||
| .Where(column => CustomAggregateCalculationMap.Keys.Contains(column)) | ||
| .Select(column => (column, CustomAggregateCalculationMap[column](gcData))) | ||
| .ToDictionary(); | ||
|
|
||
| OtherMetrics = OtherMetrics.Concat(customGCData).ToDictionary(); |
| public Dictionary<string, double[]> OriginalBaselineOtherMetrics { get; } = new(); | ||
| public Dictionary<string, double[]> OriginalComparandOtherMetrics { get; } = new(); | ||
| public Dictionary<string, double[]> OutliersFreeBaselineOtherMetrics => OriginalBaselineOtherMetrics | ||
| .Select(kvp => (kvp.Key, API.Statistics.RemoveOutliers(kvp.Value).ToArray())) | ||
| .ToDictionary(); | ||
| public Dictionary<string, double[]> OutliersFreeComparandOtherMetrics => OriginalComparandOtherMetrics | ||
| .Select(kvp => (kvp.Key, API.Statistics.RemoveOutliers(kvp.Value).ToArray())) | ||
| .ToDictionary(); |
| var comparandMicrobenchmarkResults = GoodLinq.Where(microbenchmarkResultsGroup, r => !r.Parent.is_baseline); | ||
|
|
||
| lock (_lock) | ||
| { | ||
| comparisonResults.Add(new(baselineMicrobenchmarkResults, comparandMicrobenchmarkResults, includeTraces)); |
| string outputPathForRun = Path.Combine(outputPath, run.Name); | ||
| var sortedTraceFiles = Directory.GetFiles(outputPathForRun, $"{traceFileNameTemplate}*.etl.zip", SearchOption.TopDirectoryOnly) | ||
| .OrderBy(traceFile => traceFile) | ||
| .ToArray(); |
| var ordered = comparisonResult.Comparisons.OrderByDescending(c => c.OtherMetricsDiffPerc[metric]); | ||
|
|
||
| // Large Regressions | ||
| sw.WriteLine($"### Large Regressions (>20%): {comparisonResult.LargeRegressions.Count()} \n"); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.GetDiffPercentFromOtherMetrics(metric) > 0.2)); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.OtherMetricsDiffPerc[metric] >= 0.2)); | ||
| sw.WriteLine("\n"); | ||
|
|
||
| // Large Improvements | ||
| sw.WriteLine($"### Large Improvements (>20%): {comparisonResult.LargeImprovements.Count()} \n"); | ||
| var largeImprovements = GoodLinq.Where(ordered, o => o.GetDiffPercentFromOtherMetrics(metric) < -0.2); | ||
| largeImprovements.Reverse(); | ||
| sw.AddTableForSingleCriteria(configuration, largeImprovements); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.OtherMetricsDiffPerc[metric] <= -0.2)); | ||
| sw.WriteLine("\n"); | ||
|
|
||
| // Regressions | ||
| sw.WriteLine($"### Regressions (5% - 20%): {comparisonResult.Regressions.Count()} \n"); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.GetDiffPercentFromOtherMetrics(metric) > 0.05 && o.GetDiffPercentFromOtherMetrics(metric) < 0.2)); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.OtherMetricsDiffPerc[metric] >= 0.05 && o.OtherMetricsDiffPerc[metric] < 0.2)); | ||
| sw.WriteLine("\n"); | ||
|
|
||
| // Improvements | ||
| sw.WriteLine($"### Improvements (5% - 20%): {comparisonResult.Improvements.Count()} \n"); | ||
| var improvements = GoodLinq.Where(ordered, o => o.GetDiffPercentFromOtherMetrics(metric) > 0.05 && o.GetDiffPercentFromOtherMetrics(metric) < 0.2); | ||
| improvements.Reverse(); | ||
| sw.AddTableForSingleCriteria(configuration, improvements); | ||
| sw.AddTableForSingleCriteria(configuration, GoodLinq.Where(ordered, o => o.OtherMetricsDiffPerc[metric] <= -0.05 && o.OtherMetricsDiffPerc[metric] > -0.2)); | ||
| sw.WriteLine("\n"); |
This PR aims at calculating average value of multiple microbenchmarks results. The work revolves around: