Skip to content

[Medium] CSA crowding-aware update recomputes O(n^2) bank distances per observation #34

Description

@gratus907

Severity: Medium (performance)

Under the default CSA preset (far_update_mode="crowding_aware"), every observation in a committed generation builds a fresh distance workspace and recomputes all O(n²) pairwise bank distances, though at most one entry changes per step.

Locationssrc/variopt/algorithms/population/csa/banking/update/logic.py:287-298,465-490 + banking/queries.py

_clearing_occupancy-equivalent crowding counts / niche scores are recomputed from scratch per observation via a fresh BankDistanceWorkspace, giving O(m·n²) diversity-metric calls per generation — this is the subsystem's hot loop when the diversity metric is expensive (e.g. molecular similarity).

Related, smaller instance of the same pattern: recluster (banking/update/logic.py:199-202, O(n²) distances + scipy linkage) runs at the end of every batch even when no entry changed, and advance_growth_state in multiplicative_decay mode (banking/growth/logic.py:357-395) recomputes minimum_pairwise_distance O(n²) on every tell.

Fix direction

Hoist one distance workspace to apply_bank_update_batch scope and invalidate only the rows/columns of replaced indices, rather than rebuilding per observation. Skip recluster when changed_indices is empty and reuse the batch distance workspace where possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions