Rev 5848: DirState._sort_entries was showing up for 'uncommit' times. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-uncommit-faster
John Arbash Meinel
john at arbash-meinel.com
Tue May 10 14:12:18 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.4-uncommit-faster
------------------------------------------------------------
revno: 5848
revision-id: john at arbash-meinel.com-20110510141211-2ptj7bi4piziiel8
parent: pqm at pqm.ubuntu.com-20110510102823-vf4qlngmjhgg6538
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-uncommit-faster
timestamp: Tue 2011-05-10 16:12:11 +0200
message:
DirState._sort_entries was showing up for 'uncommit' times.
This shaves a consistent 500ms off of 'uncommit' (from 15.6s to 15.1s) in
a 70k-entry tree. Basically, we cache the results of path.split('/')
rather than re-doing it for every file in every directory.
I tried implementing it via a cmp() function, to avoid split entirely
(since we have cmp_by_dirs). That seemed to make it significantly
slower, probably because of cmp() call overhead vs key.
Small win, but small change.
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2011-05-06 15:15:44 +0000
+++ b/bzrlib/dirstate.py 2011-05-10 14:12:11 +0000
@@ -2625,9 +2625,16 @@
try to keep everything in sorted blocks all the time, but sometimes
it's easier to sort after the fact.
"""
- def _key(entry):
+ split_dirs = {}
+ def _key(entry, _split_dirs=split_dirs):
# sort by: directory parts, file name, file id
- return entry[0][0].split('/'), entry[0][1], entry[0][2]
+ dirpath, fname, file_id = entry[0]
+ try:
+ split = _split_dirs[dirpath]
+ except KeyError:
+ split = tuple(dirpath.split('/'))
+ _split_dirs[dirpath] = split
+ return (split, fname, file_id)
return sorted(entry_list, key=_key)
def set_state_from_inventory(self, new_inv):
More information about the bazaar-commits
mailing list