Skip to content

⚡ Bolt: optimize backtest time-series lookups with binary search - #88

Draft
toreleon wants to merge 2 commits into
masterfrom
bolt/optimize-backtest-bar-lookups-7763250888243038433
Draft

⚡ Bolt: optimize backtest time-series lookups with binary search#88
toreleon wants to merge 2 commits into
masterfrom
bolt/optimize-backtest-bar-lookups-7763250888243038433

Conversation

@toreleon

Copy link
Copy Markdown
Owner

💡 What: Replaced Array.prototype.filter with a custom binary search function (findLastBarIndex) for locating the most recent data point (e.g., price or index value) for a given time threshold in chronologically sorted time-series arrays.
🎯 Why: In the backtest simulator (backtestRunner.ts), time-series data like prices and indexes are queried repeatedly in the inner loop (e.g. for every tick/interval turn, for every candidate ticker). Calling array.filter(b => b.time <= asOf) is an O(n) operation that causes a massive CPU bottleneck given thousands of bars and thousands of queries.
📊 Impact: Reduces time complexity of price overriding and interval index lookups from O(n) to O(log n), vastly improving CPU efficiency and simulator run time.
🔬 Measurement: Verify by running pnpm test tests/tui.test.tsx and timing a backtest simulation or manually running pnpm run test (all 87 tests should pass).


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

Replaces O(n) Array.filter with O(log n) binary search when finding bars up to a specific time threshold in the backtest runner and DNSE bar clippers. This resolves a massive CPU bottleneck during backtesting due to querying long time-series arrays thousands of times within the inner simulator 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.

Replaces O(n) Array.filter with O(log n) binary search when finding bars up to a specific time threshold in the backtest runner and DNSE bar clippers. This resolves a massive CPU bottleneck during backtesting due to querying long time-series arrays thousands of times within the inner simulator loop. Also fixes dependency vulnerabilities caught by pnpm audit.

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