浏览代码

[MLA-1742] backport SideChannel GC reduction (#4915)

/release_2_verified
GitHub 4 年前
当前提交
f6e79bdb
共有 3 个文件被更改,包括 34 次插入1 次删除
  1. 2
      com.unity.ml-agents/CHANGELOG.md
  2. 7
      com.unity.ml-agents/Runtime/Sensors/SensorShapeValidator.cs
  3. 26
      com.unity.ml-agents/Runtime/SideChannels/SideChannelsManager.cs

2
com.unity.ml-agents/CHANGELOG.md


### Bug Fixes
#### com.unity.ml-agents (C#)
- Removed unnecessary memory allocations in `SensorShapeValidator.ValidateSensors()` (#4915)
- Removed unnecessary memory allocations in `SideChannelManager.GetSideChannelMessage()` (#4915)
## [1.0.6] - 2020-11-13

7
com.unity.ml-agents/Runtime/Sensors/SensorShapeValidator.cs


{
// Check for compatibility with the other Agents' Sensors
// TODO make sure this only checks once per agent
Debug.Assert(m_SensorShapes.Count == sensors.Count, $"Number of Sensors must match. {m_SensorShapes.Count} != {sensors.Count}");
Debug.AssertFormat(
m_SensorShapes.Count == sensors.Count,
"Number of Sensors must match. {0} != {1}",
m_SensorShapes.Count,
sensors.Count
);
for (var i = 0; i < Mathf.Min(m_SensorShapes.Count, sensors.Count); i++)
{
var cachedShape = m_SensorShapes[i];

26
com.unity.ml-agents/Runtime/SideChannels/SideChannelsManager.cs


/// <returns></returns>
internal static byte[] GetSideChannelMessage(Dictionary<Guid, SideChannel> sideChannels)
{
if (!HasOutgoingMessages(sideChannels))
{
// Early out so that we don't create the MemoryStream or BinaryWriter.
// This is the most common case.
return Array.Empty<byte>();
}
using (var memStream = new MemoryStream())
{
using (var binaryWriter = new BinaryWriter(memStream))

return memStream.ToArray();
}
}
}
/// <summary>
/// Check whether any of the sidechannels have queued messages.
/// </summary>
/// <param name="sideChannels"></param>
/// <returns></returns>
static bool HasOutgoingMessages(Dictionary<Guid, SideChannel> sideChannels)
{
foreach (var sideChannel in sideChannels.Values)
{
var messageList = sideChannel.MessageQueue;
if (messageList.Count > 0)
{
return true;
}
}
return false;
}
/// <summary>

正在加载...
取消
保存