Skip to content

Commit

Permalink
Reduce allocations on list deserialization (#310)
Browse files Browse the repository at this point in the history
* Do not capture context on async awaits

* Do not capture context on async awaits (2)

* Improve list allocation when deserializing lists from messages

* Fixed List implementation with initial capacity

* Fixed list implementation for NETMF
  • Loading branch information
bmesetovic authored and xinchen10 committed Sep 20, 2018
1 parent 9a8aa1c commit 1958a1a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
15 changes: 15 additions & 0 deletions netmf/NetMF/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,20 @@ namespace Amqp.Types
/// </summary>
public class List : ArrayList
{
/// <summary>
/// Initializes a new instance of the <see cref="List"/> class.
/// </summary>
public List()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="List"/> class.
/// </summary>
/// <param name="capacity">The number of elements that the new list can initially store.</param>
public List(int capacity) : base()
{
// NOTE: NETMF ArrayList does not have a constructor that takes an int parameter, so we cannot set initial capacity in this case
}
}
}
15 changes: 15 additions & 0 deletions src/Net/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,20 @@ namespace Amqp.Types
/// </summary>
public class List : List<object>
{

/// <summary>
/// Initializes a new instance of the <see cref="List"/> class.
/// </summary>
public List()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="List"/> class.
/// </summary>
/// <param name="capacity">The number of elements that the new list can initially store.</param>
public List(int capacity) : base(capacity)
{
}
}
}
2 changes: 1 addition & 1 deletion src/Types/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ public static List ReadList(ByteBuffer buffer, byte formatCode)
throw InvalidFormatCodeException(formatCode, buffer.Offset);
}

List value = new List();
List value = new List(count);
for (int i = 0; i < count; ++i)
{
value.Add(ReadObject(buffer));
Expand Down

0 comments on commit 1958a1a

Please sign in to comment.