mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-09-29 07:12:24 +00:00
threadshare: Task: reduce memory usage
Using dynamic dispatch instead of monomorphization reduces the lib size and memory use without affecting CPU nor throughput significantly.
This commit is contained in:
parent
1bea2ad279
commit
5c9bbc6818
1 changed files with 7 additions and 6 deletions
|
@ -311,7 +311,7 @@ impl Task {
|
||||||
// FIXME allow configuration of the channel buffer size,
|
// FIXME allow configuration of the channel buffer size,
|
||||||
// this determines the contention on the Task.
|
// this determines the contention on the Task.
|
||||||
let (transition_tx, transition_rx) = async_mpsc::channel(4);
|
let (transition_tx, transition_rx) = async_mpsc::channel(4);
|
||||||
let state_machine = StateMachine::new(task_impl, transition_rx);
|
let state_machine = StateMachine::new(Box::new(task_impl), transition_rx);
|
||||||
let (transition, _) = Transition::new(TransitionKind::Prepare);
|
let (transition, _) = Transition::new(TransitionKind::Prepare);
|
||||||
inner.state_machine_handle = Some(inner.state_machine_context.spawn(state_machine.run(
|
inner.state_machine_handle = Some(inner.state_machine_context.spawn(state_machine.run(
|
||||||
Arc::clone(&self.0),
|
Arc::clone(&self.0),
|
||||||
|
@ -515,9 +515,8 @@ impl Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
struct StateMachine {
|
||||||
struct StateMachine<Impl> {
|
task_impl: Box<dyn TaskImpl>,
|
||||||
task_impl: Impl,
|
|
||||||
transition_rx: async_mpsc::Receiver<Transition>,
|
transition_rx: async_mpsc::Receiver<Transition>,
|
||||||
pending_transition: Option<Transition>,
|
pending_transition: Option<Transition>,
|
||||||
}
|
}
|
||||||
|
@ -546,8 +545,10 @@ macro_rules! spawn_hook {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Impl: TaskImpl> StateMachine<Impl> {
|
impl StateMachine {
|
||||||
fn new(task_impl: Impl, transition_rx: async_mpsc::Receiver<Transition>) -> Self {
|
// Use dynamic dispatch for TaskImpl as it reduces memory usage compared to monomorphization
|
||||||
|
// without inducing any significant performance penalties.
|
||||||
|
fn new(task_impl: Box<dyn TaskImpl>, transition_rx: async_mpsc::Receiver<Transition>) -> Self {
|
||||||
StateMachine {
|
StateMachine {
|
||||||
task_impl,
|
task_impl,
|
||||||
transition_rx,
|
transition_rx,
|
||||||
|
|
Loading…
Reference in a new issue