Skip to content

⚡ Bolt: optimize backtester tick loop to use O(log N) data lookups#49

Draft
toreleon wants to merge 2 commits into
masterfrom
bolt-optimize-backtest-lookup-17595503048858696681
Draft

⚡ Bolt: optimize backtester tick loop to use O(log N) data lookups#49
toreleon wants to merge 2 commits into
masterfrom
bolt-optimize-backtest-lookup-17595503048858696681

Conversation

@toreleon

Copy link
Copy Markdown
Owner

💡 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 test to ensure exact parity.


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

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>
@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.

- 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>
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