Title: [126374] trunk/Tools
Revision
126374
Author
[email protected]
Date
2012-08-22 18:08:25 -0700 (Wed, 22 Aug 2012)

Log Message

Baseline optimizer should try to optimize per-port if global optimization fails
https://bugs.webkit.org/show_bug.cgi?id=94665

Reviewed by Adam Barth.

Add a fallback strategy for optimizing baselines if the default
one fails; this one simply attempts to shift baselines up in the
tree and consolidates them if a parent and child in the fallback
path have the same result. This strategy is somewhat flawed in
that we will always put something in a parent dir even if we
"shouldn't"; for example, if chromium-mac produces a different
result from chromium-win and chromium-linux, then the new
algorithm will move the mac result into platform/chromium,
leaving chromium-mac empty. This result is still correct, but
perhaps confusing.

I haven't done much testing of this algorithm yet, so it's not
clear how many cases where this does a better job than the
default algorithm and how many it'll do a worse job.

* Scripts/webkitpy/common/checkout/baselineoptimizer.py:
(BaselineOptimizer._find_optimal_result_placement):
(BaselineOptimizer._optimize_by_most_specific_common_directory):
(BaselineOptimizer):
(BaselineOptimizer._optimize_by_pushing_results_up):
(BaselineOptimizer._find_in_fallbackpath):
* Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
(BaselineOptimizerTest.test_platform_mac_different):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (126373 => 126374)


--- trunk/Tools/ChangeLog	2012-08-23 01:07:22 UTC (rev 126373)
+++ trunk/Tools/ChangeLog	2012-08-23 01:08:25 UTC (rev 126374)
@@ -1,5 +1,36 @@
 2012-08-22  Dirk Pranke  <[email protected]>
 
+        Baseline optimizer should try to optimize per-port if global optimization fails
+        https://bugs.webkit.org/show_bug.cgi?id=94665
+
+        Reviewed by Adam Barth.
+
+        Add a fallback strategy for optimizing baselines if the default
+        one fails; this one simply attempts to shift baselines up in the
+        tree and consolidates them if a parent and child in the fallback
+        path have the same result. This strategy is somewhat flawed in
+        that we will always put something in a parent dir even if we
+        "shouldn't"; for example, if chromium-mac produces a different
+        result from chromium-win and chromium-linux, then the new
+        algorithm will move the mac result into platform/chromium,
+        leaving chromium-mac empty. This result is still correct, but
+        perhaps confusing.
+
+        I haven't done much testing of this algorithm yet, so it's not
+        clear how many cases where this does a better job than the
+        default algorithm and how many it'll do a worse job.
+
+        * Scripts/webkitpy/common/checkout/baselineoptimizer.py:
+        (BaselineOptimizer._find_optimal_result_placement):
+        (BaselineOptimizer._optimize_by_most_specific_common_directory):
+        (BaselineOptimizer):
+        (BaselineOptimizer._optimize_by_pushing_results_up):
+        (BaselineOptimizer._find_in_fallbackpath):
+        * Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py:
+        (BaselineOptimizerTest.test_platform_mac_different):
+
+2012-08-22  Dirk Pranke  <[email protected]>
+
         add debug info, another test to webkit-patch optimize-baselines
         https://bugs.webkit.org/show_bug.cgi?id=94762
 

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py (126373 => 126374)


--- trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py	2012-08-23 01:07:22 UTC (rev 126373)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer.py	2012-08-23 01:08:25 UTC (rev 126374)
@@ -26,6 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import copy
 import logging
 
 
@@ -125,9 +126,9 @@
         results_by_port_name = self._results_by_port_name(results_by_directory)
         port_names_by_result = _invert_dictionary(results_by_port_name)
 
-        results_by_directory, new_results_by_directory = self._optimize_by_most_specific_common_directory(results_by_directory, results_by_port_name, port_names_by_result)
+        new_results_by_directory = self._optimize_by_most_specific_common_directory(results_by_directory, results_by_port_name, port_names_by_result)
         if not new_results_by_directory:
-            pass  # FIXME: Try something else.
+            new_results_by_directory = self._optimize_by_pushing_results_up(results_by_directory, results_by_port_name, port_names_by_result)
 
         return results_by_directory, new_results_by_directory
 
@@ -144,11 +145,46 @@
             new_unsatisfied_port_names_by_result = self._filter_port_names_by_result(is_unsatisfied, port_names_by_result)
 
             if len(new_unsatisfied_port_names_by_result.values()) >= len(unsatisfied_port_names_by_result.values()):
-                break  # Frowns. We do not appear to be converging.
+                return {}  # Frowns. We do not appear to be converging.
             unsatisfied_port_names_by_result = new_unsatisfied_port_names_by_result
 
-        return results_by_directory, new_results_by_directory
+        return new_results_by_directory
 
+    def _optimize_by_pushing_results_up(self, results_by_directory, results_by_port_name, port_names_by_result):
+        results_by_directory = results_by_directory
+        best_so_far = results_by_directory
+        while True:
+            new_results_by_directory = copy.copy(best_so_far)
+            for port_name in self._hypergraph.keys():
+                fallback_path = self._hypergraph[port_name]
+                current_index, current_directory = self._find_in_fallbackpath(fallback_path, results_by_port_name[port_name], results_by_directory)
+                current_result = results_by_port_name[port_name]
+                for index in range(current_index + 1, len(fallback_path)):
+                    new_directory = fallback_path[index]
+                    if not new_directory in new_results_by_directory:
+                        new_results_by_directory[new_directory] = current_result
+                        if current_directory in new_results_by_directory:
+                            del new_results_by_directory[current_directory]
+                    elif new_results_by_directory[new_directory] == current_result:
+                        if current_directory in new_results_by_directory:
+                            del new_results_by_directory[current_directory]
+                    else:
+                        # The new_directory contains a different result, so stop trying to push results up.
+                        break
+
+            if len(new_results_by_directory) >= len(best_so_far):
+                # We've failed to improve, so give up.
+                break
+            best_so_far = new_results_by_directory
+
+        return best_so_far
+
+    def _find_in_fallbackpath(self, fallback_path, current_result, results_by_directory):
+        for index, directory in enumerate(fallback_path):
+            if directory in results_by_directory and (results_by_directory[directory] == current_result):
+                return index, directory
+        assert False, "result %s not found in fallback_path %s, %s" % (current_result, fallback_path, results_by_directory)
+
     def _filtered_results_by_port_name(self, results_by_directory):
         results_by_port_name = self._results_by_port_name(results_by_directory)
         for port_name in _VIRTUAL_PORTS.keys():

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py (126373 => 126374)


--- trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py	2012-08-23 01:07:22 UTC (rev 126373)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/baselineoptimizer_unittest.py	2012-08-23 01:08:25 UTC (rev 126374)
@@ -74,7 +74,7 @@
         })
         self.assertEqual(host.filesystem.read_binary_file('/mock-checkout/LayoutTests/platform/chromium/another/test-expected.txt'), 'result A')
 
-    def disabled_test_platform_mac_different(self):
+    def test_platform_mac_different(self):
         self._assertOptimization({
             'LayoutTests': '462d03b9c025db1b0392d7453310dbee5f9a9e74',
             'LayoutTests/platform/mac': '453e67177a75b2e79905154ece0efba6e5bfb65d',
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to