This code is running quite slowly:
public static class DB
{
readonly static InlineSql sql = new InlineSql();
public static IEnumerable<LabItem> GetLabItemsFromLabLineItems(IEnumerable<LabLineItem> items)
{
/*
* Business Rule :
* The sproc used to retrieve lab line items has no way of "grouping" lab items out of line items.
* To compensate, the sproc orders its results by IDCode, we group everything and use the first of each grouping to represent that ID Code.
* That very same item is also the first item in its Items property.
* */
return items
.GroupBy(c => c.IDCode , c => c, (c, d) => d.First())
.Select(c => new LabItem(c.IDCode, c.OrderGuid, c.Name, c.SignificantDtm, c.Status, c.Description, items.Where(d => string.Compare(d.IDCode, c.IDCode, true) == 0 )));
}
}
Particularly the select statement where we compare d.IDCode to c.IDCode appears to be the problem. This line reports a hit count of 90million from ANTS with a %Time of 14.8. items.count
is around 9 thousand.
I know my breakpoint is not hit 90 million times. What does hit count mean here?
Other useful code:
LabItem
has List<LabLineItem>
which is what we compare here. LabLineItem.Equals
:
public override bool Equals(object obj)
{
LabLineItem otherItem = obj as LabLineItem;
if (otherItem == null) return false;
return
OrderGuid == otherItem.OrderGuid
&& IDCode == otherItem.IDCode
&& SignificantDtm == otherItem.SignificantDtm
&& ObservationGuid == otherItem.ObservationGuid
&& string.Compare(Value, otherItem.Value, true) == 0;
}
public override int GetHashCode()
{
return
OrderGuid.GetHashCode()
^ IDCode.GetHashCode()
^ SignificantDtm.GetHashCode()
^ ObservationGuid.GetHashCode();
}