Skip to content

Commit 1843688

Browse files
committed
-removed sortedcontainers vendored lib
-solver benchmarking shows it's unnecessary -minor improvements within solver
1 parent d31f53c commit 1843688

File tree

7 files changed

+28
-4319
lines changed

7 files changed

+28
-4319
lines changed

src/rez/solver.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
from rez.vendor.version.requirement import VersionedObject, Requirement, \
3939
RequirementList
4040
from rez.vendor.enum import Enum
41-
from rez.vendor.sortedcontainers.sortedset import SortedSet
4241
from contextlib import contextmanager
42+
from itertools import product, chain
4343
import copy
4444
import time
4545
import sys
@@ -1419,47 +1419,46 @@ def _create_phase(status=None):
14191419
changed_scopes_i = set(range(num_scopes))
14201420
prev_num_scopes = num_scopes
14211421

1422-
# create set of pending reductions from the list of changed scopes
1423-
# and list of added scopes. We use a sorted set because the solver
1424-
# must be deterministic, ie its behavior must always be the same for
1425-
# a given solve. A normal set does not guarantee order.
1422+
# Create set of pending reductions from the list of changed scopes
1423+
# and list of added scopes. Each item is an (x, y) tuple, where
1424+
# scope[x] will reduce by scope[y].package_request.
14261425
#
1427-
# Each item is an (x, y) tuple, where scope[x] will reduce by
1428-
# scope[y].package_request.
1429-
#
1430-
pending_reducts = SortedSet()
14311426
all_scopes_i = range(num_scopes)
1427+
prev_scopes_i = range(prev_num_scopes)
14321428
added_scopes_i = range(prev_num_scopes, num_scopes)
14331429

1434-
for x in range(prev_num_scopes):
1430+
pending_reducts = set(chain(
1431+
14351432
# existing scopes must reduce against changed scopes
1436-
for y in changed_scopes_i:
1437-
if x != y:
1438-
pending_reducts.add((x, y))
1433+
product(prev_scopes_i, changed_scopes_i),
14391434

14401435
# existing scopes must reduce against newly added scopes
1441-
for y in added_scopes_i:
1442-
pending_reducts.add((x, y))
1443-
1444-
# newly added scopes must reduce against all other scopes
1445-
for x in added_scopes_i:
1446-
for y in all_scopes_i:
1447-
if x != y:
1448-
pending_reducts.add((x, y))
1449-
1450-
# 'widened' scopes (see earlier comment in this func) must reduce
1451-
# against all other scopes
1452-
for x in widened_scopes_i:
1453-
for y in all_scopes_i:
1454-
if x != y:
1455-
pending_reducts.add((x, y))
1436+
product(prev_scopes_i, added_scopes_i),
1437+
1438+
# newly added scopes must reduce against all other scopes
1439+
product(added_scopes_i, all_scopes_i),
1440+
1441+
# 'widened' scopes (see earlier comment in this func) must reduce
1442+
# against all other scopes
1443+
#
1444+
product(widened_scopes_i, all_scopes_i)
1445+
))
14561446

14571447
# iteratively reduce until there are no more pending reductions.
14581448
# Note that if a scope is reduced, then other scopes need to reduce
14591449
# against it once again.
1450+
#
14601451
with self.solver.timed(self.solver.reduction_test_time):
1452+
1453+
# A different order here wouldn't cause an invalid solve, however
1454+
# rez solves must be deterministic, so this is why we sort.
1455+
#
1456+
pending_reducts = sorted(pending_reducts)
1457+
14611458
while pending_reducts:
14621459
x, y = pending_reducts.pop()
1460+
if x == y:
1461+
continue
14631462

14641463
new_scope, reductions = scopes[x].reduce_by(
14651464
scopes[y].package_request)
@@ -1474,7 +1473,7 @@ def _create_phase(status=None):
14741473
# other scopes need to reduce against x again
14751474
for j in all_scopes_i:
14761475
if j != x:
1477-
pending_reducts.add((j, x))
1476+
pending_reducts.append((j, x))
14781477

14791478
changed_scopes_i = set()
14801479

src/rez/vendor/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ Updated (July 2019) to coincide with packaging lib addition that depends on.
236236
Also now required to support py2/3 interoperability.
237237
</td></tr>
238238

239-
<!-- ######################################################### -->
240-
<tr><td>
241-
sortedcontainers
242-
</td><td>
243-
2.4.0 (May 17, 2021)
244-
</td><td>
245-
Apache 2.0
246-
</td><td>
247-
https://github.com/grantjenks/python-sortedcontainers<br>
248-
Used in the resolver.
249-
</td></tr>
250-
251239
<!-- ######################################################### -->
252240
<tr><td>
253241
whichcraft

src/rez/vendor/sortedcontainers/LICENSE

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/rez/vendor/sortedcontainers/__init__.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)