perf(run_strategy): vectorized bar loader + preloaded_bars batch reuse#71
Merged
Merged
Conversation
_load_bars parsed the CSV and built the BarC[] with a per-bar Python/ctypes loop that was ~99% of a run's wall time (the C++ backtest itself is ~20ms at ~27M bar/s). numpy parses the whole feed at once and BarC[] shares its exact memory layout (5x float64 + 1x int64, no padding), so a single from_buffer_copy builds the array with zero per-bar Python work — 1m feed 4.93s -> 0.62s, byte-identical output. Falls back to the explicit loop when numpy is absent. Also add Strategy.run(preloaded_bars=(BarC[], n)) so a batch driver can parse the shared feed ONCE and reuse it across every strategy/candidate, skipping the CSV parse + ctypes build entirely per run. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
_load_barsparsed the CSV and builtBarC[]with a per-bar Python/ctypes loop that was ~99% of a run's wall time (the C++ backtest itself is ~20ms at ~27M bar/s).BarC[]shares its exact memory layout (5× float64 + 1× int64, no padding), so a singlefrom_buffer_copybuilds the array with zero per-bar Python work — 1m feed 4.93s → 0.62s, byte-identical output. Falls back to the explicit loop when numpy is absent.Strategy.run(preloaded_bars=(BarC[], n))lets a batch driver parse the shared feed once and reuse it across every strategy/candidate, skipping the CSV parse + ctypes build per run.Split out of the KI-35 fix (pineforge-engine#70) per review — value-neutral, corpus-proven (252/252 no demotions).
🤖 Generated with Claude Code