Improve backtest run

This commit is contained in:
2025-11-11 13:05:48 +07:00
parent c66f6279a7
commit e810ab60ce
4 changed files with 70 additions and 14 deletions

View File

@@ -241,6 +241,8 @@ public class BacktestExecutor
// Track memory usage during processing
var peakMemory = initialMemory;
const int memoryCheckInterval = 100; // Check memory every N candles to reduce GC.GetTotalMemory overhead
var lastMemoryCheck = 0;
// Start timing the candle processing loop
var candleProcessingStart = Stopwatch.GetTimestamp();
@@ -292,7 +294,6 @@ public class BacktestExecutor
await RunOptimizedBacktestStep(tradingBot);
backtestStepTotalTime += Stopwatch.GetElapsedTime(backtestStepStart);
telemetry.TotalSignalUpdates++;
telemetry.TotalBacktestSteps++;
currentCandle++;
@@ -335,11 +336,15 @@ public class BacktestExecutor
lastProgressUpdate = DateTime.UtcNow;
}
// Track peak memory usage
var currentMemory = GC.GetTotalMemory(false);
if (currentMemory > peakMemory)
// Track peak memory usage (reduced frequency to minimize GC overhead)
if (currentCandle - lastMemoryCheck >= memoryCheckInterval)
{
peakMemory = currentMemory;
var currentMemory = GC.GetTotalMemory(false);
if (currentMemory > peakMemory)
{
peakMemory = currentMemory;
}
lastMemoryCheck = currentCandle;
}
// Log progress every 10% (reduced frequency)