-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Milestone
Description
Currently some of the Consume
methods stash the reference passed to them in a local field, keeping the object alive as long as the consume object itself remains live.
BenchmarkDotNet/src/BenchmarkDotNet/Engines/Consumer.cs
Lines 98 to 109 in b78ec96
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
[PublicAPI] | |
public void Consume(string stringValue) => Volatile.Write(ref stringHolder, stringValue); | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
[PublicAPI] | |
public void Consume(object objectValue) => Volatile.Write(ref objectHolder, objectValue); | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
[PublicAPI] | |
public void Consume<T>(T objectValue) where T : class // class constraint prevents from boxing structs | |
=> Volatile.Write(ref objectHolder, objectValue); |
If that object roots a large object graph or large array allocation it can alter GC behavior and impact benchmark timing.
Consider either immediately over-writing the local field with null or nulling out this field at the end of measurement intervals.
Metadata
Metadata
Assignees
Labels
No labels