Skip to content

Disjoint sets: the members' state is boxed, so a system holding the host is small - #3045

Merged
samwhosung merged 1 commit into
samwhosung:mainfrom
Berchia:perf/boxed-sets
Nov 21, 2026
Merged

samwhosung merged 1 commit into
samwhosung:mainfrom
Berchia:perf/boxed-sets

Conversation

@Berchia

@Berchia Berchia commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What benilla did

A disjoint_set!'s state was a struct of every member's state, held inline. The call host's appliers are such a set, and ScriptCallHost's state is 181 KB.

Bevy's FunctionSystem holds Option<FunctionSystemState<P>> inline from the moment the system is made, before it is initialised. So every system that takes the host (VmWith, HostedVm, InputHost, the chat lane) is 181 KB or more while a plugin adds it. That stack goes on into_system, the boxing into dyn System, and any add_systems tuple.

Building the whole headless client (headless_client_unrun) takes about 1.5 MB of stack on Windows, and close to the 2 MB of a test thread on Linux. Any change near those systems can tip script_calls::cached_state_tests::the_hosted_vm_keeps_one_state_across_calls into a stack overflow in the Linux player-tests gate.

What changes

  • disjoint_set!'s State is Box<$state>. init_state boxes it, and get_param lends &mut **state. Nothing outside the macro changes.
  • A system holding the host now carries a pointer, not the appliers.
  • A test checks that the host's state is at most 64 bytes.

How to see it, before and after

the_hosted_vm_keeps_one_state_across_calls on a thread of a given size, player build (--no-default-features), Windows, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0 as in CI:

overflows at fits at
before 1536 KB 1538 KB
after 384 KB 416 KB

The headless client build alone needs the same as the whole test before (it overflows at 1536 KB and fits at 1538 KB), so the build is where the stack went.

Checks (Windows, without the client data)

  • cargo test -p benilla-app --lib: 7765 passed, 0 failed.
  • cargo test -p benilla-formats -p benilla-app --no-default-features --lib: 7704 and 566 passed, 0 failed, the new the_hosts_state_is_a_few_words among them.
  • cargo clippy -p benilla-ui -p benilla-app --all-targets -- -D warnings: clean.
  • cargo clippy -p benilla -p benilla-app --no-default-features -- -D warnings: clean.
    • The one warning either clippy run prints comes from the wgpu-hal dependency (bind_cbv).
  • scripts/doc-links.py: ok.
  • rustfmt --check on the changed file: clean.

@samwhosung
samwhosung merged commit 0e5c47b into samwhosung:main Nov 21, 2026
3 checks passed
@samwhosung

Copy link
Copy Markdown
Owner

Thanks, this is the real cause behind the stack overflow on #3042, and boxing the set's state is the right fix. Merged as is.

rblaine95 added a commit to bunkerlab-net/benilla that referenced this pull request Nov 22, 2026
- 53fbf8d (samwhosung#3039): Signal unit field changes through linked watchers.
- 0e5c47b (samwhosung#3045): Box disjoint system parameter state.
- 3216a7a (samwhosung#3042): Validate the optional call host once per run.

Native object packets still use the shared watcher path. The fork
has no caller of the removed watcher export and no override of the
changed host lends. Keep its separate cached-state box pending a stack
comparison. Regenerating the map and deviation index produced no diff.

Linux gates:
- `mbx fmt --all -- --check` passed.
- Strict Clippy passed for app and UI, and for app without defaults.
- App lib, installed and empty `WOW_DATA`: 9,221 of 9,221 passed in
  each configuration across the full suite and an isolated rerun;
  33 ignored each. `resident_result_transport_changed_source_allows_
  historical_ack_not_fresh_geometry` failed on a local geometry
  reply deadline at two and four threads under load. It passed in
  both configurations on the same binary with `--exact
  --test-threads=1`. The installed run had 17 GiB of swap in use.
- UI: 3,620 unit and 19 integration tests passed, 1 ignored,
  0 doctests.
- Python: verify-libtest-output 61, native-starter 182,
  classic-export 347, initial-hooks 22 passed.

Ave Deus Mechanicus
rblaine95 added a commit to bunkerlab-net/benilla that referenced this pull request Nov 22, 2026
Upstream samwhosung#3045 boxes disjoint system parameter state. The separate
fork box from 53b2e7b no longer protects the nameplate click test
from a stack overflow, so remove it and match upstream.

The exact nameplate click test passed on the default 2 MiB stack
with and without the fork box. On a 64 KiB grid, both builds
overflowed at 393,216 bytes and first passed at 458,752 bytes.
Both had 1,638,400 bytes of margin at that granularity.

Linux gates: fmt and strict Clippy passed for app plus UI, and
for app without defaults. App lib with installed WOW_DATA passed
9,221 tests with 33 ignored. With empty WOW_DATA, 9,220 passed
and 33 were ignored. The same native geometry reply deadline
seen on the boxed merge failed at four threads; it passed on
the same binary with --exact --test-threads=1. Across both runs,
the empty-data configuration passed all 9,221 tests.

Ave Deus Mechanicus
rblaine95 added a commit to bunkerlab-net/benilla that referenced this pull request Nov 22, 2026
…the verified merge

Join UpstreamMerge8's signed merge 1a42cf4 and its follow-up
1148535 onto the local P2P foundation. Upstream samwhosung#3045 boxes the
same oversized script host state as the fork's CachedState box, and
measured stack margins were identical, so the follow-up removed the
fork box and script_calls.rs now matches upstream.

The joined tree changes only the 13 client files of the verified
merge. Their contents equal 1148535. No runtime, simulation, store
or script file changes. Genmap produced no diff.

Ave Deus Mechanicus
ornfelt added a commit to ornfelt/benilla that referenced this pull request Nov 23, 2026
…ung#3042, samwhosung#3043, samwhosung#3045, samwhosung#3046 and the fork's no-change merge) merged as is - no conflicts, no gfx trigger (protocol self flag and ActivePlayerCreate, script-call host validation and boxed disjoint state, live-read routing, unit field watchers, channel cast holds), the feature-off diff against main the same lines before and after; cargo check --workspace --all-targets clean with and without benilla/gfx, benilla-protocol and benilla-ui tests green apart from lua50 table_size's a_nested_sort_costs_one_host_level_per_comparator, which reaches 58 of 150 levels at dev-fast's opt-level 0 and passes at dev, benilla-app net, creature_anim, script_calls, ui_unit, ui_chat, lanes and ui_script tests green at dev-fast, built on Windows only
ornfelt added a commit to ornfelt/benilla that referenced this pull request Nov 23, 2026
…ung#3042, samwhosung#3043, samwhosung#3045, samwhosung#3046 and the fork's no-change merge) merged as is - no conflicts, no gfx trigger (protocol self flag and ActivePlayerCreate, script-call host validation and boxed disjoint state, live-read routing, unit field watchers, channel cast holds), the branch's diff against main the same lines before and after, no schedule change (frame test green); cargo check --workspace --all-targets clean, benilla-protocol and benilla-ui tests green apart from lua50 table_size's a_nested_sort_costs_one_host_level_per_comparator, which reaches 58 of 150 levels at dev-fast's opt-level 0 and passes at dev (the eight_nested_switches_fit_a_two_megabyte_stack case again), benilla-app net, creature_anim, script_calls, ui_unit, ui_chat, lanes, ui_script and frame tests green at dev-fast, built on Windows only
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.

2 participants