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
- Single hash check per operation: Pass a "transaction context" that tracks whether the network has changed
- Lazy invalidation: Only check hash when explicitly requested, not on every property access
- 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.
Parent Issue
Part of #442 (Performance: Sub-second edits for large networks)
Problem
The selection code in
network_wrangler/roadway/selection.pycallsnetwork_hashmultiple times during a single operation:Even with an efficient hash implementation, these redundant checks add overhead.
Proposed Solution
copy.deepcopy: String hashes don't need deep copyingFiles to Modify
network_wrangler/roadway/selection.pynetwork_wrangler/transit/selection.py(if applicable)Expected Improvement
Reduces hash-related overhead from 3 calls to 1 call per operation when combined with #443.