⚡ Bolt: optimize backtester tick loop to use O(log N) data lookups#49
⚡ Bolt: optimize backtester tick loop to use O(log N) data lookups#49toreleon wants to merge 2 commits into
Conversation
Replaced O(n) array `.filter()` allocations with O(log n) binary search `findLastBarIndex` for timestamp lookups in backtester tick loop. Co-authored-by: toreleon <42534763+toreleon@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. |
- Replaced O(n) array `.filter()` allocations with O(log n) binary search `findLastBarIndex` for timestamp lookups in backtester tick loop. - Resolved CI failure: fixed dependency vulnerabilities flagged by `pnpm audit --prod --audit-level high` by bumping `undici` to `^6.27.0` and adding `ws@^8.21.0`. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
💡 What: Replaced linear array
.filter()operations with O(log n) binary search (findLastBarIndex) when looking up the latest available price up to a given timestamp inside the backtest engine's tick loop.🎯 Why: Backtests simulate many intervals and candidates. Using
.filter()on every tick for every candidate to find the most recent bar effectively creates an O(N^2) execution time bottleneck and allocates thousands of unnecessary array segments.📊 Impact: Expected to dramatically reduce execution time and garbage collection overhead during backtesting by avoiding array reallocation on the critical path.
🔬 Measurement: Verified with
pnpm testto ensure exact parity.PR created automatically by Jules for task 17595503048858696681 started by @toreleon