forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix perf regression in ShuffleRows (dotnet#5417)
RowShufflingTransformer is using ChannelReader incorrectly. It needs to block waiting for items to read and was Thread.Sleeping in order to wait, but not spin the current core. This caused a major perf regression. The fix is to block synchronously correctly - by calling AsTask() on the ValueTask that is returned from the ChannelReader and block on the Task. Fix dotnet#5416
- Loading branch information
Showing
2 changed files
with
70 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.ML.Benchmarks.Harness; | ||
using Microsoft.ML.Data; | ||
|
||
namespace Microsoft.ML.Benchmarks | ||
{ | ||
[CIBenchmark] | ||
public class ShuffleRowsBench : BenchmarkBase | ||
{ | ||
private TrainRow[] _rows; | ||
private MLContext _context; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_rows = new TrainRow[10_000]; | ||
for (var i = 0; i < _rows.Length; i++) | ||
{ | ||
_rows[i] = new TrainRow() { Sample = i.ToString(), Week = i, Label = i / 2 }; | ||
} | ||
|
||
_context = new MLContext(); | ||
} | ||
|
||
[Benchmark] | ||
public void ShuffleRows() | ||
{ | ||
IDataView data = _context.Data.LoadFromEnumerable(_rows); | ||
|
||
IDataView shuffledData = _context.Data.ShuffleRows(data, seed: 0); | ||
|
||
foreach (string sample in shuffledData.GetColumn<string>("Sample")) | ||
{ | ||
} | ||
} | ||
|
||
private class TrainRow | ||
{ | ||
[ColumnName("Sample")] | ||
public string Sample; | ||
|
||
[ColumnName("Week")] | ||
public float Week; | ||
|
||
[ColumnName("Label")] | ||
public float Label; | ||
} | ||
} | ||
} |