You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
conveyor-engine: run_coupled_passes rebuilds the compile-time-constant coupling table every Euler step #878
Found by branch review of conveyor-engine before merge (the in-flight XMILE conveyor+queue implementation; specs docs/design/conveyors.md + docs/design/queues.md). Filed from a review report that exceeded its 15-finding cap.
Summary
run_coupled_passes rebuilds the compile-time-constant coupling table (a coupling_for_conveyor Vec, a queue_is_coupled Vec, and an any flag) from the immutable queue plans on every Euler step, before the !any fast path usually discards it. A no-coupling conveyor/queue model heap-allocates and re-derives "no coupling" each dt, even though apply_couplings fixed the answer once at build time.
Failure scenario / cost
A 10,000-step Euler run of a plain one-conveyor model (queue_plans empty) executes run_coupled_passes (vm.rs:885) every step; queue_compile.rs:1132 allocates and fills vec![None; conv_plans.len()] (~10,000 pointless heap allocations), the queue-outflow scan at :1135 runs zero iterations, any stays false, and :1158 discards the table via the fast path. A model with a conveyor plus an independent uncoupled queue pays both allocations (:1132 and :1133) plus a full outflow scan (:1135-1154) each step, all still discarded. Per-step cost scales with (conveyors + queues) though the coupling never changes.
Evidence
called every step, plans borrowed immutably: crate::queue_compile::run_coupled_passes(&self.conveyor_plans, &mut self.conveyors, &self.queue_plans, ...) (src/simlin-engine/src/vm.rs:885-894), inside Method::Euler => loop { (vm.rs:831)
rebuilt each step: let mut coupling_for_conveyor: Vec<Option<CoupledServe>> = vec![None; conv_plans.len()]; (queue_compile.rs:1132), let mut queue_is_coupled = vec![false; queue_plans.len()]; (:1133), let mut any = false; (:1134), the scan (:1135), then if !any { fast path (:1157-1159)
coupling fixed once at build: op.kind = QueueOutflowKind::Coupled { inside apply_couplings (queue_compile.rs:1066), called at :898 within build_compiled
plans carry Coupled through clone/reset: if let Some(ref plans) = state.queue_plans { new_vm.set_queue_plans(plans.clone()); } (src/libsimlin/src/simulation.rs:420-424)
Suggested direction
Materialize the coupling table once in apply_couplings (or at plan-resolution time) and precompute the no-coupling bool, so the per-step pass reads it instead of rebuilding it.
Activity