Skip to content

fix: reduce on_entry/on_exit code bloat at -Oz on ARM - #743

Merged
kris-jusiak merged 1 commit into
boost-ext:masterfrom
PavelGuzenfeld:fix/issue-494-entry-exit-bloat
Nov 7, 2026
Merged

kris-jusiak merged 1 commit into
boost-ext:masterfrom
PavelGuzenfeld:fix/issue-494-entry-exit-bloat

Conversation

@PavelGuzenfeld

Copy link
Copy Markdown
Contributor

The entry/exit dispatch chain instantiates per event type. At -O2 everything inlines away, but at -Oz the lower inline threshold keeps each instantiation as a separate function — on cortex-m0 this triples .text vs a hand-written equivalent.

Adds BOOST_SML_DETAIL_ALWAYS_INLINE (__attribute__((always_inline)) / __forceinline) to the five functions in the chain: switch_stm::dispatch, process_internal_generic_event, process_internal_event, process_event_impl.

Measured on clang 23, --target=arm-arm-none-eabi -mcpu=cortex-m0 -Oz:

variant before after
on_entry/on_exit 2343 B 1321 B (−44%)
no entry/exit 701 B 701 B
-O2 / -Os unchanged unchanged

11 lines changed, no new files or dependencies.

Closes #494

The entry/exit dispatch chain (process_internal_event →
process_internal_generic_event → process_event_impl → switch_stm::dispatch)
instantiates per event type. At -O2 these inline away; at -Oz the lower
inline threshold keeps each as a separate function, tripling .text on
cortex-m0.

Mark the chain BOOST_SML_DETAIL_ALWAYS_INLINE (__attribute__((always_inline))
/ __forceinline) so the optimizer folds them regardless of -Oz threshold.

Measured on clang 23, --target=arm-arm-none-eabi -mcpu=cortex-m0 -Oz:
  .text with on_entry/on_exit: 2343 → 1321 bytes (−44%)
  .text without entry/exit:    701 → 701 (no regression)
  -O2 / -Os: unchanged

Closes boost-ext#494
@kris-jusiak
kris-jusiak merged commit 2687f64 into boost-ext:master Nov 7, 2026
7 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.

Using State OnEntry/OnExit causes non-trivial binary code bloat.

2 participants