[core] Reduce automation call chain stack depth

Force-inline the Trigger→Automation→ActionList forwarding chain
and override play_complex() in leaf action classes to skip the
virtual play() dispatch, reducing the button→lambda call stack
from 8 frames to ~4.
This commit is contained in:
J. Nick Koston
2026-03-20 18:36:07 -10:00
parent d203a46ef8
commit 34345b86fa
2 changed files with 18 additions and 3 deletions
+3 -3
View File
@@ -322,7 +322,7 @@ template<typename... Ts> class Automation;
template<typename... Ts> class Trigger {
public:
/// Inform the parent automation that the event has triggered.
void trigger(const Ts &...x) {
__attribute__((always_inline)) void trigger(const Ts &...x) {
if (this->automation_parent_ == nullptr)
return;
this->automation_parent_->trigger(x...);
@@ -429,7 +429,7 @@ template<typename... Ts> class ActionList {
this->add_action(action);
}
}
void play(const Ts &...x) {
__attribute__((always_inline)) void play(const Ts &...x) {
if (this->actions_begin_ != nullptr)
this->actions_begin_->play_complex(x...);
}
@@ -473,7 +473,7 @@ template<typename... Ts> class Automation {
void stop() { this->actions_.stop(); }
void trigger(const Ts &...x) { this->actions_.play(x...); }
__attribute__((always_inline)) void trigger(const Ts &...x) { this->actions_.play(x...); }
bool is_running() { return this->actions_.is_running(); }
+15
View File
@@ -217,6 +217,11 @@ template<typename... Ts> class LambdaAction : public Action<Ts...> {
public:
explicit LambdaAction(std::function<void(Ts...)> &&f) : f_(std::move(f)) {}
void play_complex(const Ts &...x) override {
this->num_running_++;
this->f_(x...);
this->play_next_(x...);
}
void play(const Ts &...x) override { this->f_(x...); }
protected:
@@ -230,6 +235,11 @@ template<typename... Ts> class StatelessLambdaAction : public Action<Ts...> {
public:
explicit StatelessLambdaAction(void (*f)(Ts...)) : f_(f) {}
void play_complex(const Ts &...x) override {
this->num_running_++;
this->f_(x...);
this->play_next_(x...);
}
void play(const Ts &...x) override { this->f_(x...); }
protected:
@@ -243,6 +253,11 @@ template<typename... Ts> class ContinuationAction : public Action<Ts...> {
public:
explicit ContinuationAction(Action<Ts...> *parent) : parent_(parent) {}
void play_complex(const Ts &...x) override {
this->num_running_++;
this->parent_->play_next_(x...);
this->play_next_(x...);
}
void play(const Ts &...x) override { this->parent_->play_next_(x...); }
protected: