[tor-commits] [sbws/master] Make RelayPrioritizer much faster by using sets

pastly at torproject.org pastly at torproject.org
Tue Jun 26 15:36:50 UTC 2018


commit 104fbe7952357ef78b8932b38603ef38fb3dcfab
Author: Matt Traudt <sirmatt at ksu.edu>
Date:   Fri Jun 22 09:19:13 2018 -0400

    Make RelayPrioritizer much faster by using sets
    
    GH: closes #204
---
 CHANGELOG.md                 | 6 ++++++
 sbws/lib/relayprioritizer.py | 5 ++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f9eb22..5026290 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 - Maintenance script to help us find functions that are (probably) no longer
   being called.
 
+### Fixed
+
+- Make relay priority calculations take only ~5% of the time they used to (3s
+  vs 60s) by using sets instead of lists when selecting non-Authority relays.
+(GH#204)
+
 ### Changed
 
 - Change the path where the Bandwidth List files are generated: now they are
diff --git a/sbws/lib/relayprioritizer.py b/sbws/lib/relayprioritizer.py
index a705213..3a635f0 100644
--- a/sbws/lib/relayprioritizer.py
+++ b/sbws/lib/relayprioritizer.py
@@ -46,10 +46,9 @@ class RelayPrioritizer:
         measurement.
         '''
         fn_tstart = Decimal(time.time())
-        relays = copy.deepcopy(self.relay_list.relays)
+        relays = set(copy.deepcopy(self.relay_list.relays))
         if not self.measure_authorities:
-            relays = [r for r in relays
-                      if r not in self.relay_list.authorities]
+            relays = relays.difference(set(self.relay_list.authorities))
         rd = self.result_dump
         for relay in relays:
             results = rd.results_for_relay(relay)





More information about the tor-commits mailing list