Skip to content

Consider changing Consume to not hold onto references for very long #1942

Closed
@AndyAyersMS

Description

@AndyAyersMS

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.

[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
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions