Skip to content

⚡ Bolt: Optimize time-series data lookups during backtesting#64

Draft
toreleon wants to merge 3 commits into
masterfrom
bolt/optimize-time-series-lookup-8960681477467071551
Draft

⚡ Bolt: Optimize time-series data lookups during backtesting#64
toreleon wants to merge 3 commits into
masterfrom
bolt/optimize-time-series-lookup-8960681477467071551

Conversation

@toreleon

Copy link
Copy Markdown
Owner

💡 What: Replaced array.filter(b => b.time <= asOf) with an O(log n) binary search lookup (findLastBarIndex) in the backtesting engine.

🎯 Why: During backtesting loops, the vnindexAt and priceOverride functions are called constantly for every symbol at every interval. Filtering the entire time-series array on each call results in O(n) complexity on chronologically sorted arrays. As backtests scale in interval density and candidate counts, this CPU bottleneck degrades performance significantly.

📊 Impact: Reduces time complexity of looking up historical bars from O(n) to O(log n), eliminating unnecessary array allocations and iterations. Expected to drastically improve performance for long backtesting periods.

🔬 Measurement: Verified by running the full test suite (pnpm test and pnpm typecheck), and the correctness is functionally identical while using binary search logic on sorted arrays.


PR created automatically by Jules for task 8960681477467071551 started by @toreleon

- Implement binary search utility `findLastBarIndex`
- Update `vnindexAt` and `priceOverride` in backtestRunner to use O(log n) lookups instead of `.filter`
- Add performance learning to journal

Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 2 commits June 28, 2026 15:43
- Implement binary search utility `findLastBarIndex`
- Update `vnindexAt` and `priceOverride` in backtestRunner to use O(log n) lookups instead of `.filter`
- Add performance learning to journal

Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
- Implement binary search utility `findLastBarIndex`
- Update `vnindexAt` and `priceOverride` in backtestRunner to use O(log n) lookups instead of `.filter`
- Add performance learning to journal
- Resolve high severity security vulnerabilities in CI by overriding `ws` version and updating `undici`

Co-authored-by: toreleon <42534763+toreleon@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant