Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Soccer/Ai.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Tyr.Common.Time;
using Tyr.Soccer.Plays;
using Tyr.Soccer.RoleAssignment;
using Microsoft.Extensions.Logging;
using Tyr.Soccer.Tactics;
using Command = Tyr.Common.Sender.Data.Command;
using Vision = Tyr.Common.Vision.Data;
Expand Down Expand Up @@ -148,7 +149,11 @@ public void PublishCommands()

public void Process()
{
Log.ZLogDebug($"fps: {Context.Timer.FpsSmooth}");
// Bolt: eliminates string interpolation allocation when debug logging is disabled (~100 allocs/sec)
if (Log.IsEnabled(LogLevel.Debug))
{
Log.ZLogDebug($"fps: {Context.Timer.FpsSmooth}");
}
Plot.Plot("fps", Context.Timer.Fps);

foreach (var robot in Context.OwnRobots)
Expand All @@ -173,10 +178,19 @@ public void Process()
var assignmentResult = assignmentSolver.Solve(formation, previousAssignment.RoleMapping);
var newRoleMapping = assignmentResult.RoleMapping;

Log.ZLogDebug($"Role assignment total cost: {assignmentResult.TotalCost:F3}");
foreach (var unfilledRole in assignmentResult.UnfilledRoles.Where(r => r.IsRequired))
// Bolt: eliminates string interpolation allocation when debug logging is disabled (~100 allocs/sec)
if (Log.IsEnabled(LogLevel.Debug))
{
Log.ZLogWarning($"Required role left unfilled: {unfilledRole.Role}");
Log.ZLogDebug($"Role assignment total cost: {assignmentResult.TotalCost:F3}");
}

// Bolt: eliminates ~1 enumerator & closure alloc/frame by avoiding LINQ Where() (~100 allocs/sec)
foreach (var unfilledRole in assignmentResult.UnfilledRoles)
{
if (unfilledRole.IsRequired)
{
Log.ZLogWarning($"Required role left unfilled: {unfilledRole.Role}");
}
}

Context.Data.Value = Context.Data.Value! with
Expand Down
Loading