While investigating our test suite's memory usage, NUnit also came up from some paths where a lot of parsed data was processed through loop that checked against LessThanOrEqualConstraint. If you look how all ComparisonConstraint inheritors are implemented, they all allocate Description when constructed even though I would presume it's not needed unless assertion fails?
|
public GreaterThanOrEqualConstraint(object expected) : base(expected) |
|
{ |
|
Description = "greater than or equal to " + MsgUtils.FormatValue(expected); |
|
} |
I would suggest that these would be either lazy evaluated or evaluated every time the getter is called, like for example in EqualConstraint:
|
public override string Description |
|
{ |
|
get |
|
{ |
|
System.Text.StringBuilder sb = new System.Text.StringBuilder(MsgUtils.FormatValue(_expected)); |
|
|
|
if (_tolerance != null && !_tolerance.IsUnsetOrDefault) |
|
{ |
|
sb.Append(" +/- "); |
|
sb.Append(MsgUtils.FormatValue(_tolerance.Amount)); |
|
if (_tolerance.Mode != ToleranceMode.Linear) |
|
{ |
|
sb.Append(" "); |
|
sb.Append(_tolerance.Mode.ToString()); |
|
} |
|
} |
|
|
|
if (_comparer.IgnoreCase) |
|
sb.Append(", ignoring case"); |
|
|
|
return sb.ToString(); |
|
} |
|
} |
While investigating our test suite's memory usage, NUnit also came up from some paths where a lot of parsed data was processed through loop that checked against LessThanOrEqualConstraint. If you look how all ComparisonConstraint inheritors are implemented, they all allocate Description when constructed even though I would presume it's not needed unless assertion fails?
nunit/src/NUnitFramework/framework/Constraints/GreaterThanOrEqualConstraint.cs
Lines 35 to 38 in 6f806c6
I would suggest that these would be either lazy evaluated or evaluated every time the getter is called, like for example in EqualConstraint:
nunit/src/NUnitFramework/framework/Constraints/EqualConstraint.cs
Lines 399 to 421 in 6f806c6