Rev 4707: Add a KEY_HAS_HASH define. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-memory-consumption

John Arbash Meinel john at arbash-meinel.com
Mon Sep 28 20:14:12 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-memory-consumption

------------------------------------------------------------
revno: 4707
revision-id: john at arbash-meinel.com-20090928191408-7im66hra3wfcolhz
parent: john at arbash-meinel.com-20090928190643-0hof02awxufe4q0z
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-memory-consumption
timestamp: Mon 2009-09-28 14:14:08 -0500
message:
  Add a KEY_HAS_HASH define.
  
  This turns on/off the caching of the Key.hash.
  
  For now, performance shows negligible impact of adding it,
  so it isn't worth the memory consumption. If we get into
  adding Key to a KeyDict that doesn't cache the hash
  independently, we should re-evaluate whether it is worthwhile.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx	2009-09-28 19:06:43 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx	2009-09-28 19:14:08 +0000
@@ -234,7 +234,7 @@
             loop_counter = 0
             while loop_counter < self.ref_list_length:
                 ref_list = []
-                ref_list_extend = ref_list.extend
+                ## ref_list_extend = ref_list.extend
                 # extract a reference list
                 loop_counter = loop_counter + 1
                 if last < self._start:
@@ -263,10 +263,10 @@
                     if temp_ptr == NULL:
                         # key runs to the end
                         temp_ptr = ref_ptr
-                    # PyList_Append(ref_list, self.extract_key(temp_ptr))
-                    ref_list_extend(self.extract_key(temp_ptr))
-                # ref_list = tuple(ref_list)
-                ref_list = _keys_type_c.Keys(self.key_length, *ref_list)
+                    PyList_Append(ref_list, self.extract_key(temp_ptr))
+                    ## ref_list_extend(self.extract_key(temp_ptr))
+                ref_list = tuple(ref_list)
+                ## ref_list = _keys_type_c.Keys(self.key_length, *ref_list)
                 PyList_Append(ref_lists, ref_list)
                 # prepare for the next reference list
                 self._start = next_start

=== modified file 'bzrlib/_keys_type_c.c'
--- a/bzrlib/_keys_type_c.c	2009-09-14 04:42:22 +0000
+++ b/bzrlib/_keys_type_c.c	2009-09-28 19:14:08 +0000
@@ -88,7 +88,9 @@
         return NULL;
     }
     memset(key->key_bits, 0, sizeof(PyStringObject *) * size);
+#if KEY_HAS_HASH
     key->hash = -1;
+#endif
     return (PyObject *)key;
 }
 
@@ -119,7 +121,9 @@
     if (self == NULL) {
         return NULL;
     }
+#if KEY_HAS_HASH
     self->hash = -1;
+#endif
     self->ob_size = len;
     for (i = 0; i < len; ++i) {
         obj = PyTuple_GET_ITEM(args, i);
@@ -162,9 +166,11 @@
     hashfunc string_hash;
 	long mult = 1000003L;
 
+#if KEY_HAS_HASH
     if (self->hash != -1) {
         return self->hash;
     }
+#endif
 	x = 0x345678L;
 	p = self->key_bits;
     string_hash = PyString_Type.tp_hash;
@@ -183,12 +189,14 @@
 	x += 97531L;
 	if (x == -1)
 		x = -2;
+#if KEY_HAS_HASH
     if (self->hash != -1) {
         if (self->hash != x) {
             fprintf(stderr, "hash changed: %d => %d\n", self->hash, x);
         }
     }
     self->hash = x;
+#endif
 	return x;
 }
 

=== modified file 'bzrlib/_keys_type_c.h'
--- a/bzrlib/_keys_type_c.h	2009-09-14 04:42:22 +0000
+++ b/bzrlib/_keys_type_c.h	2009-09-28 19:14:08 +0000
@@ -25,6 +25,8 @@
 #  endif
 #endif
 
+#define KEY_HAS_HASH 1
+
 /* This defines a single variable-width key.
  * It is basically the same as a tuple, but
  * 1) Lighter weight in memory
@@ -36,7 +38,9 @@
  */
 typedef struct {
     PyObject_VAR_HEAD
+#if KEY_HAS_HASH
     long hash;
+#endif
     PyStringObject *key_bits[1];
 } Key;
 extern PyTypeObject Key_Type;



More information about the bazaar-commits mailing list