⚡ Bolt: Avoid allocations in Ai.Process() hot path#39
Conversation
💡 What: - Gated `Log.ZLogDebug` calls behind `if (Log.IsEnabled(LogLevel.Debug))` to avoid string interpolation. - Replaced `.Where()` LINQ call with explicit `foreach` + `if` when evaluating unfilled roles. 🎯 Why: - `Ai.Process()` runs at ~100Hz on every frame. String interpolation evaluates regardless of logging level, causing strings to be allocated. LINQ `.Where()` causes enumerator and closure allocations. 📊 Impact: - Eliminates 3 allocs/frame (2 string interpolations, 1 LINQ enumerator). At 100Hz, this is ~300 allocs/sec avoided. 🔬 Measurement: - `dotnet-counters monitor --counters System.Runtime[gen-0-gc-count,alloc-rate]` Co-authored-by: lordhippo <5122916+lordhippo@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Log.ZLogDebugcalls behindif (Log.IsEnabled(LogLevel.Debug))to avoid string interpolation..Where()LINQ call with explicitforeach+ifwhen evaluating unfilled roles.🎯 Why:
Ai.Process()runs at ~100Hz on every frame. String interpolation evaluates regardless of logging level, causing strings to be allocated. LINQ.Where()causes enumerator and closure allocations.📊 Impact:
🔬 Measurement:
dotnet-counters monitor --counters System.Runtime[gen-0-gc-count,alloc-rate]PR created automatically by Jules for task 9005097774278763762 started by @lordhippo