perf: remove debug logging and optimize rolling window maintenance (+5.0%)

This commit is contained in:
2025-11-11 12:26:44 +07:00
parent 46966cc5d8
commit 61fdcec902
3 changed files with 15 additions and 14 deletions

View File

@@ -251,8 +251,6 @@ public class BacktestExecutor
_logger.LogInformation("🔄 Starting candle processing for {CandleCount} candles", orderedCandles.Count); _logger.LogInformation("🔄 Starting candle processing for {CandleCount} candles", orderedCandles.Count);
// Process all candles with optimized rolling window approach // 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) foreach (var candle in orderedCandles)
{ {
// Maintain rolling window efficiently using List // Maintain rolling window efficiently using List
@@ -273,11 +271,6 @@ public class BacktestExecutor
// Smart signal caching - reduce signal update frequency for performance // Smart signal caching - reduce signal update frequency for performance
// RSI and similar indicators don't need updates every candle for 15-minute data // RSI and similar indicators don't need updates every candle for 15-minute data
var shouldSkipSignalUpdate = ShouldSkipSignalUpdate(currentCandle, totalCandles); 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) if (!shouldSkipSignalUpdate)
{ {
@@ -292,12 +285,6 @@ public class BacktestExecutor
signalUpdateSkipCount++; signalUpdateSkipCount++;
// Skip signal update - reuse previous signal state // Skip signal update - reuse previous signal state
// This saves ~1ms per skipped update and improves performance significantly // 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) // Run with optimized backtest path (minimize async calls)

View File

@@ -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) // 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) if (existingPosition != null)
{ {

View File

@@ -22,3 +22,8 @@ DateTime,TestName,CandlesCount,ExecutionTimeSeconds,ProcessingRateCandlesPerSec,
2025-11-11T05:13:30Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,2.49,2300.8,15.27,13.68,25.14,2085.01,3828,33.2,232.91,0.27,0.04,24560.79,38,24.56,6015,2a0fbf9b,dev,development 2025-11-11T05:13:30Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,2.49,2300.8,15.27,13.68,25.14,2085.01,3828,33.2,232.91,0.27,0.04,24560.79,38,24.56,6015,2a0fbf9b,dev,development
2025-11-11T05:18:07Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.325,4316.5,15.25,13.83,24.63,1119.29,3828,33.2,112.94,0.15,0.02,24560.79,38,24.56,6015,1792cd23,dev,development 2025-11-11T05:18:07Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.325,4316.5,15.25,13.83,24.63,1119.29,3828,33.2,112.94,0.15,0.02,24560.79,38,24.56,6015,1792cd23,dev,development
2025-11-11T05:21:03Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.015,5659.9,15.27,10.17,24.65,886.92,3828,33.2,58.10,0.12,0.01,24560.79,38,24.56,6015,1792cd23,dev,development 2025-11-11T05:21:03Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.015,5659.9,15.27,10.17,24.65,886.92,3828,33.2,58.10,0.12,0.01,24560.79,38,24.56,6015,1792cd23,dev,development
2025-11-11T05:22:42Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.025,5602.9,15.26,10.15,24.61,898.21,3828,33.2,58.23,0.12,0.01,24560.79,38,24.56,6015,46966cc5,dev,development
2025-11-11T05:24:05Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,2.73,2099.4,15.27,11.24,25.12,2350.71,3828,33.2,172.82,0.31,0.03,24560.79,38,24.56,6015,46966cc5,dev,development
2025-11-11T05:24:53Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.82,3151.4,15.26,11.16,24.64,1547.05,3828,33.2,128.87,0.20,0.02,24560.79,38,24.56,6015,46966cc5,dev,development
2025-11-11T05:25:48Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.87,3069.1,15.26,11.10,24.65,1634.11,3828,33.2,118.83,0.21,0.02,24560.79,38,24.56,6015,46966cc5,dev,development
2025-11-11T05:26:29Z,ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry,5760,1.265,4533.9,15.27,11.26,24.66,1075.57,3828,33.2,89.65,0.14,0.02,24560.79,38,24.56,6015,46966cc5,dev,development
1 DateTime TestName CandlesCount ExecutionTimeSeconds ProcessingRateCandlesPerSec MemoryStartMB MemoryEndMB MemoryPeakMB SignalUpdatesCount SignalUpdatesSkipped SignalUpdateEfficiencyPercent BacktestStepsCount AverageSignalUpdateMs AverageBacktestStepMs FinalPnL WinRatePercent GrowthPercentage Score CommitHash GitBranch Environment
22 2025-11-11T05:13:30Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 2.49 2300.8 15.27 13.68 25.14 2085.01 3828 33.2 232.91 0.27 0.04 24560.79 38 24.56 6015 2a0fbf9b dev development
23 2025-11-11T05:18:07Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.325 4316.5 15.25 13.83 24.63 1119.29 3828 33.2 112.94 0.15 0.02 24560.79 38 24.56 6015 1792cd23 dev development
24 2025-11-11T05:21:03Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.015 5659.9 15.27 10.17 24.65 886.92 3828 33.2 58.10 0.12 0.01 24560.79 38 24.56 6015 1792cd23 dev development
25 2025-11-11T05:22:42Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.025 5602.9 15.26 10.15 24.61 898.21 3828 33.2 58.23 0.12 0.01 24560.79 38 24.56 6015 46966cc5 dev development
26 2025-11-11T05:24:05Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 2.73 2099.4 15.27 11.24 25.12 2350.71 3828 33.2 172.82 0.31 0.03 24560.79 38 24.56 6015 46966cc5 dev development
27 2025-11-11T05:24:53Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.82 3151.4 15.26 11.16 24.64 1547.05 3828 33.2 128.87 0.20 0.02 24560.79 38 24.56 6015 46966cc5 dev development
28 2025-11-11T05:25:48Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.87 3069.1 15.26 11.10 24.65 1634.11 3828 33.2 118.83 0.21 0.02 24560.79 38 24.56 6015 46966cc5 dev development
29 2025-11-11T05:26:29Z ExecuteBacktest_With_Large_Dataset_Should_Show_Performance_Telemetry 5760 1.265 4533.9 15.27 11.26 24.66 1075.57 3828 33.2 89.65 0.14 0.02 24560.79 38 24.56 6015 46966cc5 dev development