Rev 4652: Using PyObject_RichCompareBool is a significant benefit. 8.8ms down to 7.7ms. in http://bazaar.launchpad.net/~jameinel/bzr/2.0b1-stable-groupcompress-order

John Arbash Meinel john at arbash-meinel.com
Tue Sep 1 20:58:23 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.0b1-stable-groupcompress-order

------------------------------------------------------------
revno: 4652
revision-id: john at arbash-meinel.com-20090901195817-trar1zxe03u6cfah
parent: john at arbash-meinel.com-20090901150647-za59rk55lhixgeqc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0b1-stable-groupcompress-order
timestamp: Tue 2009-09-01 14:58:17 -0500
message:
  Using PyObject_RichCompareBool is a significant benefit. 8.8ms down to 7.7ms.
-------------- next part --------------
=== modified file 'bzrlib/_known_graph_pyx.pyx'
--- a/bzrlib/_known_graph_pyx.pyx	2009-09-01 15:06:47 +0000
+++ b/bzrlib/_known_graph_pyx.pyx	2009-09-01 19:58:17 +0000
@@ -26,6 +26,8 @@
         pass
 
     int PyString_CheckExact(object)
+    int Py_LT
+    int PyObject_RichCompareBool(object, object, int)
 
     int PyTuple_CheckExact(object)
     object PyTuple_New(Py_ssize_t n)
@@ -149,9 +151,9 @@
             node1 = _get_list_node(lst_or_tpl, 0)
             node2 = _get_list_node(lst_or_tpl, 1)
         if reverse:
-            do_swap = (node1.key < node2.key)
+            do_swap = PyObject_RichCompareBool(node1.key, node2.key, Py_LT)
         else:
-            do_swap = (node2.key < node1.key)
+            do_swap = PyObject_RichCompareBool(node2.key, node1.key, Py_LT)
         if not do_swap:
             return lst_or_tpl
         if is_tuple:
@@ -510,17 +512,15 @@
                     # Ghost
                     continue
                 PyList_Append(result, node.key)
-                # Do we need to sort the parent keys? They are always in a
-                # 'stable' order because it is something we track and preserve.
-                # Sorting here costs us 10.9ms down from 5.9ms if we just
-                # walk them directly.
-                # 45.2ms => 34.8ms for all file graphs
-                ## parents = _sort_list_nodes(node.parents, 0)
-                ## for pos from len(parents) > pos >= 0:
+                # Sorting the parent keys isn't strictly necessary for stable
+                # sorting of a given graph. But it does help minimize the
+                # differences between graphs
+                # For bzr.dev ancestry:
+                #   4.73ms  no sort
+                #   8.78ms  < sort
+                #   7.73ms  RichCompareBool sort
                 parents = _sort_list_nodes(node.parents, 1)
                 for pos from 0 <= pos < len(parents):
-                ## parents = node.parents
-                ## for pos from len(parents) > pos >= 0:
                     if PyTuple_CheckExact(parents):
                         parent_node = _get_tuple_node(parents, pos)
                     else:



More information about the bazaar-commits mailing list