perf(decimal): d_sum_iter eliminates Vec in CustomStrategy (#372)#374
Merged
Conversation
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
Owner
Author
|
@copilot review |
Copilot stopped work on behalf of
joaquinbejar due to an error
April 19, 2026 19:21
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.
Summary
d_sum_iter<I: IntoIterator<Item = Decimal>>(iter, op)next tod_suminsrc/model/decimal.rs; same overflow-tagging semantics, zero allocation.d_sumnow delegates tod_sum_iterso slice and iterator entry points stay in lock-step.CustomStrategy::calculate_profit_atastry_foldoverself.positions+d_add, removing theVec<Decimal>collected on every pricing call.d_sum, lazymapadapter, and overflow-tag preservation.Closes #372.
Test plan
cargo test --lib --all-features(4 pre-existing unrelated failures underchains::chain::tests_basic_curves/tests_option_chain_surfaces; all new tests pass, 3753 total pass).cargo clippy --lib --all-features --all-targets -- -D warningscargo fmt --all --check