Skip to content

Commit 63b62a9

Browse files
committed
Updated comment from feedback.
Added conditional compilation around thread sleep.
1 parent 31f280d commit 63b62a9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/BenchmarkDotNet/Engines/Engine.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,18 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
225225
var exceptionsStats = new ExceptionsStats(); // allocates
226226
exceptionsStats.StartListening(); // this method might allocate
227227

228+
#if !NET7_0_OR_GREATER
228229
if (RuntimeInformation.IsNetCore && Environment.Version.Major is >= 3 and <= 6 && RuntimeInformation.IsTieredJitEnabled)
229230
{
230231
// #1542
231232
// We put the current thread to sleep so tiered jit can kick in, compile its stuff,
232233
// and NOT allocate anything on the background thread when we are measuring allocations.
233-
// This is only an issue on netcoreapp3.0 to net6.0. Tiered jit allocations were fixed in net7.0,
234+
// This is only an issue on netcoreapp3.0 to net6.0. Tiered jit allocations were "fixed" in net7.0
235+
// (maybe not completely eliminated forever, but at least reduced to a point where measurements are much more stable),
234236
// and netcoreapp2.X uses only GetAllocatedBytesForCurrentThread which doesn't capture the tiered jit allocations.
235237
Thread.Sleep(TimeSpan.FromMilliseconds(500));
236238
}
239+
#endif
237240

238241
// GC collect before measuring allocations.
239242
ForceGcCollect();

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace BenchmarkDotNet.IntegrationTests
2929
public class MemoryDiagnoserTests
3030
{
3131
// TODO: re-enable allocating tests after https://github.com/dotnet/runtime/issues/101536 is fixed.
32-
private const string AllocatingSkipReason = "System.Runtime.InteropServices.RuntimeInformation allocates during GC collect";
32+
private const string AllocatingSkipReason = "GC collect causes allocations on finalizer thread";
3333

3434
private readonly ITestOutputHelper output;
3535

0 commit comments

Comments
 (0)