Skip to content

Performance: Reduce redundant network_hash calls in selection #444

@e-lo

Description

@e-lo

Parent Issue

Part of #442 (Performance: Sub-second edits for large networks)

Problem

The selection code in network_wrangler/roadway/selection.py calls network_hash multiple times during a single operation:

# selection.py:149 - On selection creation
self._stored_net_hash = copy.deepcopy(self.net.network_hash)

# selection.py:345-346 - When getting selected links (called twice!)
if self._selected_links_df is None or self._stored_net_hash != self.net.network_hash:
    self._stored_net_hash = copy.deepcopy(self.net.network_hash)

Even with an efficient hash implementation, these redundant checks add overhead.

Proposed Solution

  1. Single hash check per operation: Pass a "transaction context" that tracks whether the network has changed
  2. Lazy invalidation: Only check hash when explicitly requested, not on every property access
  3. Remove redundant copy.deepcopy: String hashes don't need deep copying
# Before
self._stored_net_hash = copy.deepcopy(self.net.network_hash)

# After  
self._stored_net_hash = self.net.network_hash  # Strings are immutable

Files to Modify

  • network_wrangler/roadway/selection.py
  • network_wrangler/transit/selection.py (if applicable)

Expected Improvement

Reduces hash-related overhead from 3 calls to 1 call per operation when combined with #443.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions