Rev 5376: get into the nitty gritty for the _key_to_sha1 function. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf

John Arbash Meinel john at arbash-meinel.com
Wed Aug 4 05:33:28 BST 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf

------------------------------------------------------------
revno: 5376
revision-id: john at arbash-meinel.com-20100804043324-1ldc2v2w1kza7ox4
parent: john at arbash-meinel.com-20100804020038-teb38durhgj6psxj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-btree-chk-leaf
timestamp: Tue 2010-08-03 23:33:24 -0500
message:
  get into the nitty gritty for the _key_to_sha1 function.
  
  It doesn't seem to help to op-out of the actual unhexlify call, so at least
  that doesn't seem to be the performance overhead.
  We get down to around 19.9us for _key_to_sha1 across 120 keys, which is
  0.166us per key.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2010-08-04 02:00:38 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2010-08-04 04:33:24 +0000
@@ -70,7 +70,8 @@
 # local names to access them.
 from _static_tuple_c cimport StaticTuple, \
     import_static_tuple_c, StaticTuple_New, \
-    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact
+    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact, \
+    StaticTuple_GET_SIZE, StaticTuple_GET_ITEM
 
 
 # TODO: Find some way to import this from _dirstate_helpers
@@ -419,14 +420,19 @@
     :return: 1 if this could be converted, 0 otherwise
     """
     cdef char *c_val
-    if not PyTuple_CheckExact(key) and not StaticTuple_CheckExact(key):
-        return 0
-    if len(key) != 1:
-        return 0
-    val = key[0]
-    if not PyString_CheckExact(val) or PyString_GET_SIZE(val) != 45:
-        return 0
-    c_val = PyString_AS_STRING(val)
+    cdef PyObject *p_val
+
+    if StaticTuple_CheckExact(key) and StaticTuple_GET_SIZE(key) == 1:
+        p_val = <PyObject *>StaticTuple_GET_ITEM(key, 0)
+    elif (PyTuple_CheckExact(key) and PyTuple_GET_SIZE(key) == 1):
+        p_val = PyTuple_GET_ITEM_ptr_object(key, 0)
+    else:
+        # Not a tuple or a StaticTuple
+        return 0
+    if (PyString_CheckExact_ptr(p_val) and PyString_GET_SIZE_ptr(p_val) == 45):
+        c_val = PyString_AS_STRING_ptr(p_val)
+    else:
+        return 0
     if strncmp(c_val, 'sha1:', 5) != 0:
         return 0
     if not _unhexlify_sha1(c_val + 5, sha1):
@@ -573,6 +579,9 @@
         # The _LeafNode.__getitem__ takes 54.6us, but (k in o._keys) is 20.7us
         # removing the getattr() w/ (k in _keys) 13.7ms. So we do still have
         # some room for improvement
+        # _key_to_sha1 takes 24us, which puts a lower bound on _lookup_record
+        # unless we skip doing the whole record (iterating is 8us,
+        # iterating+no-op C function call is 12.5us)
         # TODO: Consider improving this, but for now it seems good enough. (We
         #       could create a small index so we would have less to bisect,
         #       etc.)



More information about the bazaar-commits mailing list