Disjoint sets box their state, so a system holding the host is small (#3045)
A `disjoint_set!` held every member's state inline, and `ScriptCallHost`'s is 181 KB. Bevy keeps a system's param state inline from the moment the system is made, so every system that takes the host was 181 KB or more on the stack while a plugin added it. Building the headless client came close to a Linux test thread's 2 MB, and any change near those systems could overflow `the_hosted_vm_keeps_one_state_across_calls`. The set's state is now boxed; nothing outside the macro changes. A test holds the host's state to at most 64 bytes. On Windows, that test's stack need drops from about 1.5 MB to about 400 KB. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
@@ -63,16 +63,17 @@ macro_rules! disjoint_set {
|
||||
// holds outside the set ([`crate::script_calls::disjoint::gather`]), and lends one member
|
||||
// at a time, through `&mut self`.
|
||||
unsafe impl bevy::ecs::system::SystemParam for $name<'_, '_> {
|
||||
type State = $state;
|
||||
// Boxed, as a system holds its params' state inline from the moment it is added.
|
||||
type State = Box<$state>;
|
||||
type Item<'w, 's> = $name<'w, 's>;
|
||||
|
||||
fn init_state(world: &mut bevy::ecs::world::World) -> Self::State {
|
||||
$state {
|
||||
Box::new($state {
|
||||
$(
|
||||
$(#[cfg($cfg)])?
|
||||
$field: <$ty as bevy::ecs::system::SystemParam>::init_state(world),
|
||||
)*
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn init_access(
|
||||
@@ -142,7 +143,7 @@ macro_rules! disjoint_set {
|
||||
change_tick: bevy::ecs::change_detection::Tick,
|
||||
) -> Self::Item<'w, 's> {
|
||||
$name {
|
||||
states: state,
|
||||
states: &mut **state,
|
||||
meta: meta.clone(),
|
||||
world,
|
||||
change_tick,
|
||||
@@ -387,6 +388,15 @@ mod tests {
|
||||
|
||||
use super::Pair;
|
||||
|
||||
/// A system holds the host's state inline from the moment it is added.
|
||||
#[test]
|
||||
fn the_hosts_state_is_a_few_words() {
|
||||
use crate::script_calls::ScriptCallHost;
|
||||
use bevy::ecs::system::SystemParam;
|
||||
let size = size_of::<<ScriptCallHost<'static, 'static> as SystemParam>::State>();
|
||||
assert!(size <= 64, "{size}");
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
struct Cell(u32);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user