Skip to content

perf(decimal): d_sum_iter eliminates Vec in CustomStrategy (#372)#374

Merged
joaquinbejar merged 1 commit into
mainfrom
issue-372-d-sum-iter
Apr 19, 2026
Merged

perf(decimal): d_sum_iter eliminates Vec in CustomStrategy (#372)#374
joaquinbejar merged 1 commit into
mainfrom
issue-372-d-sum-iter

Conversation

@joaquinbejar
Copy link
Copy Markdown
Owner

Summary

  • Add d_sum_iter<I: IntoIterator<Item = Decimal>>(iter, op) next to d_sum in src/model/decimal.rs; same overflow-tagging semantics, zero allocation.
  • d_sum now delegates to d_sum_iter so slice and iterator entry points stay in lock-step.
  • Rewrite CustomStrategy::calculate_profit_at as try_fold over self.positions + d_add, removing the Vec<Decimal> collected on every pricing call.
  • Unit tests cover empty iter, happy path equal to d_sum, lazy map adapter, and overflow-tag preservation.

Closes #372.

Test plan

  • cargo test --lib --all-features (4 pre-existing unrelated failures under chains::chain::tests_basic_curves / tests_option_chain_surfaces; all new tests pass, 3753 total pass).
  • cargo clippy --lib --all-features --all-targets -- -D warnings
  • cargo fmt --all --check

Add iterator-based `d_sum_iter<I: IntoIterator<Item = Decimal>>` helper
beside `d_sum` in `src/model/decimal.rs`. Delegate `d_sum` to the new
helper so the checked-arithmetic/overflow-tagging semantics stay in
lock-step.

Rewrite `CustomStrategy::calculate_profit_at` as a `try_fold` over
`self.positions` that accumulates leg pay-offs with `d_add`, removing
the intermediate `Vec<Decimal>` that previously allocated on every
option-price evaluation.

Add unit tests covering empty iterator, happy path (matching `d_sum`),
lazy `map` adapters, and overflow-tag preservation.

Closes #372
@joaquinbejar joaquinbejar requested review from Copilot and removed request for Copilot April 19, 2026 19:09
@joaquinbejar
Copy link
Copy Markdown
Owner Author

@copilot review

@joaquinbejar joaquinbejar merged commit cc50366 into main Apr 19, 2026
14 of 16 checks passed
@joaquinbejar joaquinbejar deleted the issue-372-d-sum-iter branch April 19, 2026 19:20
Copilot stopped work on behalf of joaquinbejar due to an error April 19, 2026 19:21
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.

Add iterator-based d_sum_iter helper and eliminate Vec allocation in custom::calculate_profit_at

1 participant