5 This tool can help to reduce the memory usage in very large builds featuring many tasks with after/before attributes.
6 It may also improve the overall build time by decreasing the amount of iterations over tasks.
10 opt.load('mem_reducer')
14 from waflib import Utils, Task, Runner
16 class SetOfTasks(object):
17 """Wraps a set and a task which has a list of other sets.
18 The interface is meant to mimic the interface of set. Add missing functions as needed.
20 def __init__(self, owner):
21 self._set = owner.run_after
25 for g in self._owner.run_after_groups:
29 for task in self._set:
35 def update(self, obj):
38 def set_precedence_constraints(tasks):
39 cstr_groups = Utils.defaultdict(list)
41 x.run_after = SetOfTasks(x)
42 x.run_after_groups = []
45 h = x.hash_constraints()
46 cstr_groups[h].append(x)
48 # create sets which can be reused for all tasks
49 for k in cstr_groups.keys():
50 cstr_groups[k] = set(cstr_groups[k])
52 # this list should be short
53 for key1, key2 in itertools.combinations(cstr_groups.keys(), 2):
54 group1 = cstr_groups[key1]
55 group2 = cstr_groups[key2]
56 # get the first entry of the set
57 t1 = next(iter(group1))
58 t2 = next(iter(group2))
60 # add the constraints based on the comparisons
61 if Task.is_before(t1, t2):
63 x.run_after_groups.append(group1)
65 k.waiting_sets.append(group1)
66 elif Task.is_before(t2, t1):
68 x.run_after_groups.append(group2)
70 k.waiting_sets.append(group2)
72 Task.set_precedence_constraints = set_precedence_constraints
77 self.add_more_tasks(tsk)
84 except AttributeError:
94 Runner.Parallel.get_out = get_out
97 tsk.hasrun = Task.SKIPPED
101 ws = tsk.waiting_sets
102 except AttributeError:
110 Runner.Parallel.skip = skip