Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: pylib/gyp/input.py

Issue 234813003: gyp: fix O(n^2) in dependency calculations. (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 Google Inc. All rights reserved. 1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from compiler.ast import Const 5 from compiler.ast import Const
6 from compiler.ast import Dict 6 from compiler.ast import Dict
7 from compiler.ast import Discard 7 from compiler.ast import Discard
8 from compiler.ast import List 8 from compiler.ast import List
9 from compiler.ast import Module 9 from compiler.ast import Module
10 from compiler.ast import Node 10 from compiler.ast import Node
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 1473
1474 def __repr__(self): 1474 def __repr__(self):
1475 return '<DependencyGraphNode: %r>' % self.ref 1475 return '<DependencyGraphNode: %r>' % self.ref
1476 1476
1477 def FlattenToList(self): 1477 def FlattenToList(self):
1478 # flat_list is the sorted list of dependencies - actually, the list items 1478 # flat_list is the sorted list of dependencies - actually, the list items
1479 # are the "ref" attributes of DependencyGraphNodes. Every target will 1479 # are the "ref" attributes of DependencyGraphNodes. Every target will
1480 # appear in flat_list after all of its dependencies, and before all of its 1480 # appear in flat_list after all of its dependencies, and before all of its
1481 # dependents. 1481 # dependents.
1482 flat_list = [] 1482 flat_list = []
1483 flat_set = set()
scottmg 2014/04/11 18:28:26 comment here to the effect that _set is for optimi
Daniel Bratell 2014/04/14 12:18:27 Done.
1483 1484
1484 # in_degree_zeros is the list of DependencyGraphNodes that have no 1485 # in_degree_zeros is the list of DependencyGraphNodes that have no
1485 # dependencies not in flat_list. Initially, it is a copy of the children 1486 # dependencies not in flat_list. Initially, it is a copy of the children
1486 # of this node, because when the graph was built, nodes with no 1487 # of this node, because when the graph was built, nodes with no
1487 # dependencies were made implicit dependents of the root node. 1488 # dependencies were made implicit dependents of the root node.
1488 in_degree_zeros = set(self.dependents[:]) 1489 in_degree_zeros = set(self.dependents[:])
1489 1490
1490 while in_degree_zeros: 1491 while in_degree_zeros:
1491 # Nodes in in_degree_zeros have no dependencies not in flat_list, so they 1492 # Nodes in in_degree_zeros have no dependencies not in flat_list, so they
1492 # can be appended to flat_list. Take these nodes out of in_degree_zeros 1493 # can be appended to flat_list. Take these nodes out of in_degree_zeros
1493 # as work progresses, so that the next node to process from the list can 1494 # as work progresses, so that the next node to process from the list can
1494 # always be accessed at a consistent position. 1495 # always be accessed at a consistent position.
1495 node = in_degree_zeros.pop() 1496 node = in_degree_zeros.pop()
1496 flat_list.append(node.ref) 1497 flat_list.append(node.ref)
1498 flat_set.add(node.ref)
1497 1499
1498 # Look at dependents of the node just added to flat_list. Some of them 1500 # Look at dependents of the node just added to flat_list. Some of them
1499 # may now belong in in_degree_zeros. 1501 # may now belong in in_degree_zeros.
1500 for node_dependent in node.dependents: 1502 for node_dependent in node.dependents:
1501 is_in_degree_zero = True 1503 is_in_degree_zero = True
1504 # TODO: We want to check through the
1505 # node_dependent.dependencies list but if it's long and we
1506 # always start at the beginning, then we get O(n^2) behaviour.
1502 for node_dependent_dependency in node_dependent.dependencies: 1507 for node_dependent_dependency in node_dependent.dependencies:
1503 if not node_dependent_dependency.ref in flat_list: 1508 if not node_dependent_dependency.ref in flat_set:
1504 # The dependent one or more dependencies not in flat_list. There 1509 # The dependent one or more dependencies not in flat_list. There
1505 # will be more chances to add it to flat_list when examining 1510 # will be more chances to add it to flat_list when examining
1506 # it again as a dependent of those other dependencies, provided 1511 # it again as a dependent of those other dependencies, provided
1507 # that there are no cycles. 1512 # that there are no cycles.
1508 is_in_degree_zero = False 1513 is_in_degree_zero = False
1509 break 1514 break
1510 1515
1511 if is_in_degree_zero: 1516 if is_in_degree_zero:
1512 # All of the dependent's dependencies are already in flat_list. Add 1517 # All of the dependent's dependencies are already in flat_list. Add
1513 # it to in_degree_zeros where it will be processed in a future 1518 # it to in_degree_zeros where it will be processed in a future
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 ValidateRunAsInTarget(target, target_dict, build_file) 2820 ValidateRunAsInTarget(target, target_dict, build_file)
2816 ValidateActionsInTarget(target, target_dict, build_file) 2821 ValidateActionsInTarget(target, target_dict, build_file)
2817 2822
2818 # Generators might not expect ints. Turn them into strs. 2823 # Generators might not expect ints. Turn them into strs.
2819 TurnIntIntoStrInDict(data) 2824 TurnIntIntoStrInDict(data)
2820 2825
2821 # TODO(mark): Return |data| for now because the generator needs a list of 2826 # TODO(mark): Return |data| for now because the generator needs a list of
2822 # build files that came in. In the future, maybe it should just accept 2827 # build files that came in. In the future, maybe it should just accept
2823 # a list, and not the whole data dict. 2828 # a list, and not the whole data dict.
2824 return [flat_list, targets, data] 2829 return [flat_list, targets, data]
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698