refactor(attrs): apply #[inline]/#[cold]+#[inline(never)] (#339)#375
Merged
Conversation
…#339) - `#[inline]` on hot-path public entry points and small accessors in `strategies/*`, `pnl/*`, `greeks/utils`, `pricing/{payoff,utils}`, `risk/span`, `volatility/utils`, etc. following the audit in `rules/global_rules.md` §Compiler Attributes. - `#[inline(never)]` on large / rarely-taken constructors such as `CustomStrategy::new` and other multi-arg builders that the optimiser has no business inlining. - `#[cold] #[inline(never)]` on every error constructor across `error/*` (`DecimalError::{overflow, arithmetic_error, conversion_error, out_of_bounds, invalid_precision, invalid_value}`, `PricingError::{method_error, simulation_error, invalid_engine, other, unsupported_option_type, non_finite}`, and the equivalents in `greeks`, `volatility`, `simulation`, `strategies`, `options`, `position`, `probability`, `chains`, `curves`, `surfaces`, `trade`) so panic / error paths don't pollute the inlining budget of the happy path. `#[inline(always)]` intentionally _not_ added here: the rules require a Criterion benchmark demonstrating the win first. That audit is tracked by the benchmark work on numeric kernels and will land in a follow-up PR. Closes #339
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
#[inline]on small hot-path helpers and public entry points instrategies/*,pnl/*,greeks/utils,pricing/{payoff,utils},risk/span,volatility/utils,series/*,chains/*.#[inline(never)]on multi-arg / rarely-called builders such asCustomStrategy::new.#[cold] #[inline(never)]on every error constructor acrosssrc/error/*so error paths don't eat the inlining budget of the happy path (DecimalError::{overflow, arithmetic_error, conversion_error, out_of_bounds, invalid_precision, invalid_value},PricingError::{method_error, simulation_error, invalid_engine, other, unsupported_option_type, non_finite}, and equivalents ingreeks,volatility,simulation,strategies,options,position,probability,chains,curves,surfaces,trade).#[inline(always)]deliberately not added here — the rules require a Criterion benchmark demonstrating the win first; that audit lives with the numeric-kernel benchmark work in a follow-up.Closes #339.
Test plan
cargo build --lib --all-featurescargo clippy --lib --all-features --all-targets -- -D warningscargo fmt --all --checkcargo test --lib --all-features— 3753 pass; 4 pre-existing unrelated failures underchains::chainalso fail onmain.