perf: remove debug logging and optimize rolling window maintenance (+5.0%)
This commit is contained in:
@@ -251,8 +251,6 @@ public class BacktestExecutor
|
||||
_logger.LogInformation("🔄 Starting candle processing for {CandleCount} candles", orderedCandles.Count);
|
||||
|
||||
// Process all candles with optimized rolling window approach
|
||||
_logger.LogInformation("🎯 Starting to process {Count} candles in loop", orderedCandles.Count);
|
||||
Console.WriteLine("CONSOLE: About to start candle processing loop");
|
||||
foreach (var candle in orderedCandles)
|
||||
{
|
||||
// Maintain rolling window efficiently using List
|
||||
@@ -273,11 +271,6 @@ public class BacktestExecutor
|
||||
// Smart signal caching - reduce signal update frequency for performance
|
||||
// RSI and similar indicators don't need updates every candle for 15-minute data
|
||||
var shouldSkipSignalUpdate = ShouldSkipSignalUpdate(currentCandle, totalCandles);
|
||||
if (currentCandle <= 5) // Debug first few candles
|
||||
{
|
||||
_logger.LogInformation("🔍 Candle {CurrentCandle}: shouldSkip={ShouldSkip}, totalCandles={Total}",
|
||||
currentCandle, shouldSkipSignalUpdate, totalCandles);
|
||||
}
|
||||
|
||||
if (!shouldSkipSignalUpdate)
|
||||
{
|
||||
@@ -292,12 +285,6 @@ public class BacktestExecutor
|
||||
signalUpdateSkipCount++;
|
||||
// Skip signal update - reuse previous signal state
|
||||
// This saves ~1ms per skipped update and improves performance significantly
|
||||
if (signalUpdateSkipCount <= 5) // Log first few skips for debugging
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"⏭️ Signal update skipped for candle {CurrentCandle} (total skipped: {SkipCount})",
|
||||
currentCandle, signalUpdateSkipCount);
|
||||
}
|
||||
}
|
||||
|
||||
// Run with optimized backtest path (minimize async calls)
|
||||
|
||||
@@ -428,7 +428,16 @@ public class TradingBotBase : ITradingBot
|
||||
}
|
||||
|
||||
// Check if we already have a position for this signal (in case it was added but not processed yet)
|
||||
var existingPosition = Positions.Values.FirstOrDefault(p => p.SignalIdentifier == signal.Identifier);
|
||||
// Optimized: Avoid LINQ FirstOrDefault overhead
|
||||
Position existingPosition = null;
|
||||
foreach (var pos in Positions.Values)
|
||||
{
|
||||
if (pos.SignalIdentifier == signal.Identifier)
|
||||
{
|
||||
existingPosition = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (existingPosition != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user