Skip to content

Assembly: selecting a body nested deep in a large assembly stalls the window for seconds #7502

Closed

Description

@N3MI-DG

Reproduced on: SolidCraft 0.24.0, built from source at 3ad5a360 (main), release profile, Linux x86_64, Vulkan.

Design: an imported STEP assembly with about 400 bodies spread across many nested sub-assemblies, with the top-level occurrence active. Timings were taken with SOLIDCRAFT_PROFILE_FRAMES=1 plus temporary frame timers. Stack traces were sampled with gdb.

Steps

  1. Open a large STEP assembly whose parts sit several levels deep in nested sub-assemblies, and wait for loading to finish.
  2. Keep the Browser shown, with Select bodies on.
  3. Click a body near the top of the tree. It selects at once.
  4. Click a body several levels deep.

Expected

A deeply nested body selects as quickly as one near the top, within a frame or two.

Actual

The window freezes for about 4.4 s, every time such a body is clicked:

Body clicked Pick Browser Highlight build GPU upload Total
Near the top of the tree 1–44 ms 1–3 ms 10–31 ms ~13 ms < 0.1 s
Several levels deep 1–7 ms 1,360–1,520 ms 2,865–2,900 ms small ~4.4 s

The pick, the GPU upload and the drawing are cheap, and the world state is not placed again (its cache does not miss). The time goes into listing the bodies under occurrences.

Where the time goes

Session::occurrence_bodies costs (subtree size) × (design size)

occurrence_bodies(path, true) → expand_occurrence_bodies calls occurrence_placement once for every occurrence in the subtree (crates/engine/src/occurrences.rs:195–252). Each call does work proportional to the whole design:

  • it builds a new WorldNames (hash maps over every occurrence and every body), then frees it (crates/doc/src/assembly.rs:439, occurrences.rs:173, 191);
  • it filters every model body to find the component's own (model_body_component(b) == component);
  • it walks the path with linear finds over doc.occurrences.

Every stack sample taken during the stall was inside this expansion: either building WorldNames (WorldNames::new) or freeing it at the end of occurrence_placement.

Browser reveal: about 1.5 s (confirmed by stack samples)

After a viewport pick, reveal_pick sets tree.reveal. While drawing, each component row then calls reveals_in_occurrence (crates/ui-egui/src/browser.rs:656). That function runs occurrence_bodies(path, true) on the row's whole subtree, just to test whether the picked body is in it:

WorldNames::new                     crates/doc/src/assembly.rs:439
occurrence_placement                crates/engine/src/occurrences.rs:173
occurrence_children                 crates/engine/src/occurrences.rs:205
expand_occurrence_bodies            crates/engine/src/occurrences.rs:252
occurrence_bodies_shared            crates/engine/src/occurrences.rs:224
occurrence_bodies                   crates/engine/src/occurrences.rs:210
reveals_in_occurrence               crates/ui-egui/src/browser.rs:656
occurrence_rows_inner               crates/ui-egui/src/browser.rs:1325
occurrence_rows / component_rows    crates/ui-egui/src/browser.rs:1311, 1284, 1175

The deeper the body, the more rows get asked, and each row's question costs a subtree expansion.

Highlight build: about 2.9 s (indicated by timers; not stack-sampled)

All of this time falls in the first section of build_highlight (crates/ui-egui/src/viewport.rs:3180–3201). The only costly call there is occurrence_bodies(active_occurrence_path, true) (viewport.rs:3192). With the top-level occurrence active, that lists the whole assembly.

The answer is cached in occurrence_bodies_shared, but the cache holds at most OCCURRENCE_BODIES_CACHED = 256 paths and is cleared entirely once full (occurrences.rs:46, 226). The reveal's row-by-row queries most likely fill it, which evicts the active occurrence's entry, so the next highlight build expands the whole assembly again.

The same active-occurrence query also runs during picking (crates/ui-egui/src/view_pick.rs:131) and scene building (viewport.rs:1192, 4910). The context menu, select.set and Browser hover call occurrence_bodies too.

Fix suggestions

These are suggestions only; they are independent, and maintainers may prefer other approaches.

  • Name every placed body once per design and evaluated model. Build a placement index in one walk: each occurrence path's component and bodies' world names, and each parent's children. Do it the way Document::body_frames_with_source and the world-state build already do, with one WorldNames and bodies grouped by component once. occurrence_placement and expand_occurrence_bodies would then look things up instead of rebuilding them, so a listing costs the subtree's size, not subtree × design. Names depend on neither pending moves nor the active component, so the index could be keyed on the document and model alone. Keeping today's walk as a fallback above MAX_PLACEMENTS would keep the current limits and errors.
  • Open the Browser from the picked body's path instead of asking every row. Find the revealed body's occurrence path once (browser_model::Model::body_path already does this for Find in Browser), then open a row when that path starts with the row's own. No engine query per row, and the reveal no longer fills the shared cache.
  • Evict single entries from OccurrenceBodiesCache instead of clearing it. Once the first suggestion is in, a cleared cache costs little. Without it, keeping the active occurrence's entry would avoid the full re-expansion seen here.

Related work

STEP File Used for Testing

https://github.com/bigtreetech/BIGTREETECH-Kraken/blob/master/3D/BIGTREETECH%20Kraken%20V1.0.zip

Activity

  1. added
    area:doc
    needs-triage
    on Oct 27, 2026
  2. dahakbuilds commented on Oct 27, 2026

    @dahakbuilds
    Contributor

    Triage by Dahak (agent): confirmed in source at 38dedcca (upstream/main, checked 2026-10-27); the stall itself is GUI-interaction so it was not re-clicked here, but every mechanism in the report checks out against current main (line numbers shifted slightly since 3ad5a360):

    • Session::occurrence_placement (crates/engine/src/occurrences.rs:143) builds a fresh WorldNames::new(&self.doc, &state) on every call (occurrences.rs:173). WorldNames::new (crates/doc/src/assembly.rs:433) is O(design): hash maps over every occurrence plus a set over every model body. It also filters every model body per call and does linear finds over doc.occurrences per path element.
    • expand_occurrence_bodies (occurrences.rs:241) pops every occurrence in the subtree and calls occurrence_children → occurrence_placement per child, so a descendant listing costs (subtree size) × (design size), as reported.
    • Browser reveal: reveals_in_occurrence is now at crates/ui-egui/src/browser.rs:730 and still runs occurrence_bodies(path, true) on each row's subtree to test containment.
    • Highlight build: build_highlight (crates/ui-egui/src/viewport.rs:3179) calls occurrence_bodies(active_occurrence_path, true) at viewport.rs:3191; the same query also runs in view_pick.rs:131 and scene building (viewport.rs:1192, viewport.rs:4899).
    • Cache eviction: OCCURRENCE_BODIES_CACHED = 256 (occurrences.rs:46); once full, occurrence_bodies_shared replaces the whole cache with a fresh empty one (occurrences.rs:226) rather than evicting single entries, so the row-by-row reveal queries evict the active occurrence's entry and the next highlight re-expands the whole assembly.

    Not a kernel-paused area (engine/UI performance), so this is fixable independently of the kernel pause. The report's own timings (Browser reveal ~1.5 s, highlight build ~2.9 s on a ~400-body STEP assembly) were taken by the reporter on 3ad5a360 with frame timers and gdb samples.

  3. added
    in progress
    on Oct 27, 2026
  4. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    Claimed by @dahakbuilds through #7694. The claim lapses after 14 days without pushes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:docin progressneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions