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

Unified Diff: Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py

Issue 1182253003: Parsing expectations is n^2 in the number of tests per line. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: improve comment Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
diff --git a/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py b/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
index afb63367b06e64a5ed4c0eeb7018aba8ee0c62c7..7a0ab9dc876b79fff234c694d662c9868474b45b 100644
--- a/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
+++ b/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py
@@ -30,6 +30,8 @@
for layout tests.
"""
+from collections import defaultdict
+
import logging
import re
@@ -562,10 +564,26 @@ class TestExpectationsModel(object):
def merge_model(self, other):
self._merge_test_map(self._test_to_expectations, other._test_to_expectations)
- for test, line in other._test_to_expectation_line.items():
+ # merge_expectation_lines is O(tests per line). Therefore, this loop
+ # is O((tests per line)^2) which is really expensive when a line
+ # contains a lot of tests. Cache the output of merge_expectation_lines
+ # so that we only call that n^2 in the number of *lines*.
+ merge_lines_cache = defaultdict(dict)
+
+ for test, other_line in other._test_to_expectation_line.items():
+ merged_line = None
if test in self._test_to_expectation_line:
- line = TestExpectationLine.merge_expectation_lines(self._test_to_expectation_line[test], line, model_all_expectations=False)
- self._test_to_expectation_line[test] = line
+ self_line = self._test_to_expectation_line[test]
+
+ if other_line not in merge_lines_cache[self_line]:
+ merge_lines_cache[self_line][other_line] = TestExpectationLine.merge_expectation_lines(
+ self_line, other_line, model_all_expectations=False)
+
+ merged_line = merge_lines_cache[self_line][other_line]
+ else:
+ merged_line = other_line
+
+ self._test_to_expectation_line[test] = merged_line
self._merge_dict_of_sets(self._expectation_to_tests, other._expectation_to_tests)
self._merge_dict_of_sets(self._timeline_to_tests, other._timeline_to_tests)
« 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