Rev 4673: Speed up the innermost btree parsing function. in lp:///~jameinel/bzr/2.1-btree-simple-parse
John Arbash Meinel
john at arbash-meinel.com
Fri Sep 4 21:57:48 BST 2009
At lp:///~jameinel/bzr/2.1-btree-simple-parse
------------------------------------------------------------
revno: 4673
revision-id: john at arbash-meinel.com-20090904204912-e6mvz39tpx6u2ii2
parent: pqm at pqm.ubuntu.com-20090904024310-7a3uqlf6iruxvz6m
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-btree-simple-parse
timestamp: Fri 2009-09-04 15:49:12 -0500
message:
Speed up the innermost btree parsing function.
When extracting a key, instead of parsing into a list, and then
casting that into a tuple, just pre-allocate the tuple (we know the
size anyway), and then parse.
This saves approx 10% of the time to parse a btree index.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx 2009-06-22 12:52:39 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx 2009-09-04 20:49:12 +0000
@@ -41,8 +41,11 @@
int PyString_AsStringAndSize_ptr(PyObject *, char **buf, Py_ssize_t *len)
void PyString_InternInPlace(PyObject **)
int PyTuple_CheckExact(object t)
+ object PyTuple_New(Py_ssize_t n_entries)
+ void PyTuple_SET_ITEM(object, Py_ssize_t offset, object) # steals the ref
Py_ssize_t PyTuple_GET_SIZE(object t)
PyObject *PyTuple_GET_ITEM_ptr_object "PyTuple_GET_ITEM" (object tpl, int index)
+ void Py_INCREF(object)
void Py_DECREF_ptr "Py_DECREF" (PyObject *)
cdef extern from "string.h":
@@ -141,7 +144,7 @@
cdef int loop_counter
# keys are tuples
loop_counter = 0
- key_segments = []
+ key = PyTuple_New(self.key_length)
while loop_counter < self.key_length:
loop_counter = loop_counter + 1
# grab a key segment
@@ -164,8 +167,9 @@
temp_ptr - self._start)
# advance our pointer
self._start = temp_ptr + 1
- PyList_Append(key_segments, key_element)
- return tuple(key_segments)
+ Py_INCREF(key_element)
+ PyTuple_SET_ITEM(key, loop_counter - 1, key_element)
+ return key
cdef int process_line(self) except -1:
"""Process a line in the bytes."""
More information about the bazaar-commits
mailing list