Rev 4047: Create a one-shot cache of the result of RemoteBzrDir.create_branch, eliminating 3 round trips for nonstacked branches and 5 for stacked. in http://people.ubuntu.com/~robertc/baz2.0/push.roundtrips
Robert Collins
robertc at robertcollins.net
Wed Feb 25 04:28:45 GMT 2009
At http://people.ubuntu.com/~robertc/baz2.0/push.roundtrips
------------------------------------------------------------
revno: 4047
revision-id: robertc at robertcollins.net-20090225042842-jwojup508avng2hc
parent: robertc at robertcollins.net-20090225042748-l0n1e8v5osu8dgd8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: push.roundtrips
timestamp: Wed 2009-02-25 15:28:42 +1100
message:
Create a one-shot cache of the result of RemoteBzrDir.create_branch, eliminating 3 round trips for nonstacked branches and 5 for stacked.
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-02-25 00:31:09 +0000
+++ b/bzrlib/remote.py 2009-02-25 04:28:42 +0000
@@ -96,6 +96,9 @@
# this object holds a delegated bzrdir that uses file-level operations
# to talk to the other side
self._real_bzrdir = None
+ # 1-shot cache for the call pattern 'create_branch; open_branch' - see
+ # create_branch for details.
+ self._next_open_branch_result = None
if _client is None:
medium = transport.get_smart_medium()
@@ -123,6 +126,12 @@
def _translate_error(self, err, **context):
_translate_error(err, bzrdir=self, **context)
+ def break_lock(self):
+ # Prevent aliasing problems in the next_open_branch_result cache.
+ # See create_branch for rationale.
+ self._next_open_branch_result = None
+ return BzrDir.break_lock(self)
+
def cloning_metadir(self, stacked=False):
self._ensure_real()
return self._real_bzrdir.cloning_metadir(stacked)
@@ -146,14 +155,23 @@
# be parameterised.
real_branch = self._format.get_branch_format().initialize(self)
if not isinstance(real_branch, RemoteBranch):
- return RemoteBranch(self, self.find_repository(), real_branch)
+ result = RemoteBranch(self, self.find_repository(), real_branch)
else:
- return real_branch
+ result = real_branch
+ # BzrDir.clone_on_transport() uses the result of create_branch but does
+ # not return it to its callers; we save approximately 8% of our round
+ # trips by handing the branch we created back to the first caller to
+ # open_branch rather than probing anew. Long term we need a API in
+ # bzrdir that doesn't discard result objects (like result_branch).
+ # RBC 20090225
+ self._next_open_branch_result = result
+ return result
def destroy_branch(self):
"""See BzrDir.destroy_branch"""
self._ensure_real()
self._real_bzrdir.destroy_branch()
+ self._next_open_branch_result = None
def create_workingtree(self, revision_id=None, from_branch=None):
raise errors.NotLocalUrl(self.transport.base)
@@ -187,6 +205,11 @@
def open_branch(self, _unsupported=False):
if _unsupported:
raise NotImplementedError('unsupported flag support not implemented yet.')
+ if self._next_open_branch_result is not None:
+ # See create_branch for details.
+ result = self._next_open_branch_result
+ self._next_open_branch_result = None
+ return result
reference_url = self.get_branch_reference()
if reference_url is None:
# branch at this location.
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-02-24 21:22:43 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-02-25 04:28:42 +0000
@@ -202,7 +202,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertEqual(32, rpc_count)
+ self.assertEqual(29, rpc_count)
def test_push_smart_stacked_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -219,7 +219,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertEqual(61, rpc_count)
+ self.assertEqual(56, rpc_count)
remote = Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
More information about the bazaar-commits
mailing list