Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(run_strategy): vectorized bar loader + preloaded_bars batch reuse#71

Merged
luisleo526 merged 1 commit into
mainfrom
perf/run-strategy-vectorized-loader
Jul 7, 2026
Merged

perf(run_strategy): vectorized bar loader + preloaded_bars batch reuse#71
luisleo526 merged 1 commit into
mainfrom
perf/run-strategy-vectorized-loader

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

What

_load_bars parsed the CSV and built 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).

  • Vectorized load: numpy parses the whole feed at once; BarC[] shares its exact memory layout (5× float64 + 1× 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.
  • Batch reuse: 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

_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]>
@luisleo526 luisleo526 merged commit 7b89017 into main Jul 7, 2026
5 checks passed
@luisleo526 luisleo526 deleted the perf/run-strategy-vectorized-loader branch July 7, 2026 04:52
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