Merge lp:~jameinel/bzr/2.2-move-to-front-if-changed-562429 into lp:bzr

Proposed by John A Meinel
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jameinel/bzr/2.2-move-to-front-if-changed-562429
Merge into: lp:bzr
Diff against target: 66 lines (+25/-9)
2 files modified
NEWS (+4/-0)
bzrlib/index.py (+21/-9)
To merge this branch: bzr merge lp:~jameinel/bzr/2.2-move-to-front-if-changed-562429
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+23371@code.launchpad.net

Description of the change

I haven't actually confirmed that this fixes bug #562429, but it fits the symptoms, and it does fix a problem that *I* encountered.

Basically, spiv's new 'reorder indexes' code works well, but it tries to re-order even when the indexes are already at the beginning.

This is a pretty trivial change, but in my case:
  branch.revision_history()

drops from 1.4s down to 0.62s.

To post a comment you must log in.
Revision history for this message
Andrew Bennetts (spiv) wrote :

Makes sense, and thanks for improving my code!

I wonder if it would be faster again to teach iter_entries not to call _move_to_front at all if len(hit_indices) == num. of times it looped through 'for index in self._indices'? Probably not much.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-04-14 04:35:47 +0000
+++ NEWS 2010-04-14 05:26:34 +0000
@@ -67,6 +67,10 @@
67 read calls. An incremental pull via plain HTTP takes half the time and67 read calls. An incremental pull via plain HTTP takes half the time and
68 bytes for a moderately large repository. (Andrew Bennetts)68 bytes for a moderately large repository. (Andrew Bennetts)
6969
70* Index lookups only re-order the indexes when the hit files aren't
71 already first. Reduces the cost of reordering
72 (John Arbash Meinel, #562429)
73
70* Less code is loaded at startup. (Cold-cache start time is about 10-20%74* Less code is loaded at startup. (Cold-cache start time is about 10-20%
71 less.)75 less.)
72 (Martin Pool, #553017)76 (Martin Pool, #553017)
7377
=== modified file 'bzrlib/index.py'
--- bzrlib/index.py 2010-04-08 07:01:10 +0000
+++ bzrlib/index.py 2010-04-14 05:26:34 +0000
@@ -1418,6 +1418,10 @@
1418 _move_to_front propagates to all objects in self._sibling_indices by1418 _move_to_front propagates to all objects in self._sibling_indices by
1419 calling _move_to_front_by_name.1419 calling _move_to_front_by_name.
1420 """1420 """
1421 if self._indices[:len(hit_indices)] == hit_indices:
1422 # The 'hit_indices' are already at the front (and in the same
1423 # order), no need to re-order
1424 return
1421 hit_names = self._move_to_front_by_index(hit_indices)1425 hit_names = self._move_to_front_by_index(hit_indices)
1422 for sibling_idx in self._sibling_indices:1426 for sibling_idx in self._sibling_indices:
1423 sibling_idx._move_to_front_by_name(hit_names)1427 sibling_idx._move_to_front_by_name(hit_names)
@@ -1431,19 +1435,27 @@
1431 if 'index' in debug.debug_flags:1435 if 'index' in debug.debug_flags:
1432 mutter('CombinedGraphIndex reordering: currently %r, promoting %r',1436 mutter('CombinedGraphIndex reordering: currently %r, promoting %r',
1433 indices_info, hit_indices)1437 indices_info, hit_indices)
1434 hit_indices_info = []
1435 hit_names = []1438 hit_names = []
1436 unhit_indices_info = []1439 unhit_names = []
1437 for name, idx in indices_info:1440 new_hit_indices = []
1441 unhit_indices = []
1442
1443 for offset, (name, idx) in enumerate(indices_info):
1438 if idx in hit_indices:1444 if idx in hit_indices:
1439 info = hit_indices_info
1440 hit_names.append(name)1445 hit_names.append(name)
1446 new_hit_indices.append(idx)
1447 if len(new_hit_indices) == len(hit_indices):
1448 # We've found all of the hit entries, everything else is
1449 # unhit
1450 unhit_names.extend(self._index_names[offset+1:])
1451 unhit_indices.extend(self._indices[offset+1:])
1452 break
1441 else:1453 else:
1442 info = unhit_indices_info1454 unhit_names.append(name)
1443 info.append((name, idx))1455 unhit_indices.append(idx)
1444 final_info = hit_indices_info + unhit_indices_info1456
1445 self._indices = [idx for (name, idx) in final_info]1457 self._indices = new_hit_indices + unhit_indices
1446 self._index_names = [name for (name, idx) in final_info]1458 self._index_names = hit_names + unhit_names
1447 if 'index' in debug.debug_flags:1459 if 'index' in debug.debug_flags:
1448 mutter('CombinedGraphIndex reordered: %r', self._indices)1460 mutter('CombinedGraphIndex reordered: %r', self._indices)
1449 return hit_names1461 return hit_names