Skip to content

refactor(attrs): apply #[inline]/#[cold]+#[inline(never)] (#339)#375

Merged
joaquinbejar merged 2 commits into
mainfrom
issue-339-compiler-attributes
Apr 19, 2026
Merged

refactor(attrs): apply #[inline]/#[cold]+#[inline(never)] (#339)#375
joaquinbejar merged 2 commits into
mainfrom
issue-339-compiler-attributes

Conversation

@joaquinbejar

Copy link
Copy Markdown
Owner

Summary

  • #[inline] on small hot-path helpers and public entry points in strategies/*, pnl/*, greeks/utils, pricing/{payoff,utils}, risk/span, volatility/utils, series/*, chains/*.
  • #[inline(never)] on multi-arg / rarely-called builders such as CustomStrategy::new.
  • #[cold] #[inline(never)] on every error constructor across src/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 in greeks, 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-features
  • cargo clippy --lib --all-features --all-targets -- -D warnings
  • cargo fmt --all --check
  • cargo test --lib --all-features — 3753 pass; 4 pre-existing unrelated failures under chains::chain also fail on main.

…#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
@joaquinbejar joaquinbejar merged commit fffc85d into main Apr 19, 2026
10 of 11 checks passed
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.

Apply #[inline]/[always]/[never]/[cold] per hot-path and error-path rules

1 participant