⚡ Bolt: Fast O(log n) binary search for time-series backtest lookups#62
⚡ Bolt: Fast O(log n) binary search for time-series backtest lookups#62toreleon wants to merge 3 commits into
Conversation
…es lookups This commit introduces a reusable `findLastBarIndex` utility function that performs a binary search to find the correct index in an array of chronologically sorted market data bars. It replaces the O(n) `.filter()` array methods used in `clipBars`, `vnindexAt` and `priceOverride` with this O(log n) lookup. This completely avoids allocating large intermediate filtered arrays during backtest loops, drastically speeding up data retrieval. 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. |
…erabilities This commit introduces a reusable `findLastBarIndex` utility function that performs a binary search to find the correct index in an array of chronologically sorted market data bars. It replaces the O(n) `.filter()` array methods used in `clipBars`, `vnindexAt` and `priceOverride` with this O(log n) lookup. This completely avoids allocating large intermediate filtered arrays during backtest loops, drastically speeding up data retrieval. Additionally, this commit updates `undici`, `ws`, and `cheerio` to their latest versions to fix high-severity vulnerabilities flagged by `pnpm audit` during the CI build process. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
undici 8.5.0 caused a webidl uncloneable error during tests (TypeError: webidl.util.markAsUncloneable is not a function). Downgrading to 7.28.0 still fixes the security vulnerabilities flagged by pnpm audit while maintaining test compatibility. Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
💡 What: Replaced O(n)
.filter()operations with an O(log n) binary search (findLastBarIndex) for looking up chronological time-series data.🎯 Why: In
src/agent/backtestRunner.ts, thevnindexAtandpriceOverridefunctions are called repeatedly in a backtest loop. Previously, these functions used.filter(b => b.time <= asOf)to search for the most recent data point, causing massive array allocations and full O(n) iterations for every lookup on large market data sets.📊 Impact: This reduces the algorithmic complexity of time-series lookups from O(n) to O(log n) and eliminates the creation of intermediate arrays. Backtest loops with fine-grained cadences over large time windows will see a drastic decrease in CPU overhead and memory allocation.
🔬 Measurement: Verified by ensuring the
vitesttest suite still passes. The performance improvement can be measured by running a long backtest and observing the reduced CPU and memory footprint during the backtest turn loop.PR created automatically by Jules for task 11057315843125864955 started by @toreleon