Skip to content

ltm-finding: SearchGraph clones Ident<Canonical> in per-timestep DFS hot path #481

Closed

Description

@bpowers

Summary

SearchGraph in src/simlin-engine/src/ltm_finding.rs keys its data on Ident<Canonical> (String-backed) and clones identifiers into hash maps on every recursive DFS call. The strongest-path discovery runs per saved timestep, so for a 1000-variable model with 500 saved timesteps this is on the order of 5x10^7 String-keyed map operations per run; element-level expansion makes it far worse.

Locations

  • src/simlin-engine/src/ltm_finding.rs:63-65 -- SearchGraph { adj: HashMap<Ident<Canonical>, ...>, stocks: Vec<Ident<Canonical>>, ... }
  • src/simlin-engine/src/ltm_finding.rs:186-237 -- check_outbound_uses: best_score: &mut HashMap<Ident<Canonical>, f64> and visiting: &mut HashSet<Ident<Canonical>> with .insert(variable.clone(), ...) per recursive call

Suggested fix

Apply the same NodeId indexing pattern that IndexedGraph uses in the exhaustive-enumeration path (ltm.rs):

  • Per-timestep Vec<u32>-indexed SearchGraph (precompute name -> node_id once)
  • Dense Vec<f64> for best_score, Vec<bool> for visiting
  • Reset by re-zeroing the small per-SCC slice rather than allocating a fresh map

Expected 5-10x speedup on large discovery runs based on the analogous gain seen when the exhaustive path was indexed.

Severity

medium (performance, no correctness impact)

References

Activity

  1. added
    engine
    ltm
    on May 1, 2026
  2. added a commit that references this issue on Aug 20, 2026
    9fdfb5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions