Skip to content

Commit 9ffcfe8

Browse files
authored
Limit StructValue resize allocations (#2107)
1 parent 4685da6 commit 9ffcfe8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/TraceEvent/DynamicTraceEventParser.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ private object GetPayloadValueAt(ref PayloadFetch payloadFetch, int offset, int
603603
PayloadFetchClassInfo classInfo = payloadFetch.Class;
604604
if (classInfo != null)
605605
{
606-
var ret = new StructValue();
606+
var ret = new StructValue(classInfo.FieldFetches.Length);
607607

608608
for (int i = 0; i < classInfo.FieldFetches.Length; i++)
609609
{
@@ -797,6 +797,10 @@ private object GetPayloadValueAt(ref PayloadFetch payloadFetch, int offset, int
797797
/// </summary>
798798
internal class StructValue : IDictionary<string, object>
799799
{
800+
internal StructValue(int capacity = 0)
801+
{
802+
m_values = new List<KeyValuePair<string, object>>(capacity);
803+
}
800804
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() { return m_values.GetEnumerator(); }
801805
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return m_values.GetEnumerator(); }
802806
public bool IsReadOnly { get { return true; } }
@@ -937,7 +941,7 @@ public bool ContainsKey(string key)
937941
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex) { throw new NotImplementedException(); }
938942
public bool Remove(KeyValuePair<string, object> item) { throw new NotImplementedException(); }
939943

940-
private List<KeyValuePair<string, object>> m_values = new List<KeyValuePair<string, object>>();
944+
private List<KeyValuePair<string, object>> m_values;
941945
#endregion
942946
}
943947

0 commit comments

Comments
 (0)