Skip to content

ltm: element-level loop finding spends most of its time on strings #955

Closed as not planned

Description

@bpowers

On arrayed models where element-level loop finding enumerates many loops, most of the time goes to per-loop string work (building subscripted names, rotating each loop to a canonical start, building sort keys), not to the graph search itself.

Example

square_owner_whole_rhs_declines_and_skips_loudly in tests/integration/ltm_array_agg.rs (a 4-variable model, 8 elements) takes about 2.9 s in a debug build, against about 0.3 s for similar tests.
A perf profile spreads the time over build_element_subscripted_links, lex_smallest_rotation_start, loop_id_sort_key, johnson_circuit, strip_subscript, and identifier canonicalization and allocation.

Why it matters

Seen only in that fixture.
#1017 has the minimal reproduction and the diagnosis: those loops are all discarded afterwards because they pass through a link LTM cannot score.

Fix

Do canonical rotation and id sorting on integer node ids, and build strings only for loops that survive.
Track this together with #1017; skipping the discarded loops there may remove the case that motivated this.

Pointers

  • src/simlin-engine/src/db/ltm/loops.rs: build_element_subscripted_links
  • src/simlin-engine/src/ltm/mod.rs: lex_smallest_rotation_start, strip_subscript
  • src/simlin-engine/src/ltm/graph.rs: loop_id_sort_key
  • src/simlin-engine/src/ltm/indexed.rs: johnson_circuit

Activity

  1. added
    ltm
    on Jul 12, 2026
  2. changed the title [-]engine: LTM element-level circuit enumeration spends most of its time in string canonicalization/rotation churn (cross-product shapes)[/-] [+]ltm: element-level loop finding spends most of its time on strings[/+] on Oct 12, 2026
  3. added
    bug
    duplicate
    on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing as a duplicate of #1017.

    Same test and same slow path as #1017, which has the minimal repro and diagnosis; integer-id rotation is folded into #1017 as the alternative fix.

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

    bugduplicateltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions