-
Notifications
You must be signed in to change notification settings - Fork 5
Performance: Reduce redundant network_hash calls in selection #444
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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 immutableFiles 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request