Rev 3531: Make bzrlib.smart use lazy imports. in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/lazy_medium
John Arbash Meinel
john at arbash-meinel.com
Sat Jul 12 19:08:59 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/lazy_medium
------------------------------------------------------------
revno: 3531
revision-id: john at arbash-meinel.com-20080712180848-34lm6j0zthd8k3t9
parent: pqm at pqm.ubuntu.com-20080707230506-82h5w03vc72dyf1a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lazy_medium
timestamp: Sat 2008-07-12 13:08:48 -0500
message:
Make bzrlib.smart use lazy imports.
It saves us an import of ssh.py that we aren't using, which
on windows saves us an import of paramiko, which saves us from
creating a Crypto.util.randompool.RandomPool, which spends
1.5s measuring the delta between ticks of time.time()
Mostly, this just means when you run a single test, it takes 100ms,
rather than 1.5s of setup time, to spend 100ms running the actual
test.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py 2008-06-25 05:21:31 +0000
+++ b/bzrlib/smart/medium.py 2008-07-12 18:08:48 +0000
@@ -29,21 +29,17 @@
import sys
import urllib
+from bzrlib.lazy_import import lazy_import
+lazy_import(globals(), """
from bzrlib import (
errors,
osutils,
symbol_versioning,
urlutils,
)
-from bzrlib.smart.protocol import (
- MESSAGE_VERSION_THREE,
- REQUEST_VERSION_TWO,
- SmartClientRequestProtocolOne,
- SmartServerRequestProtocolOne,
- SmartServerRequestProtocolTwo,
- build_server_protocol_three
- )
+from bzrlib.smart import protocol
from bzrlib.transport import ssh
+""")
def _get_protocol_factory_for_bytes(bytes):
@@ -67,14 +63,14 @@
root_client_path. unused_bytes are any bytes that were not part of a
protocol version marker.
"""
- if bytes.startswith(MESSAGE_VERSION_THREE):
- protocol_factory = build_server_protocol_three
- bytes = bytes[len(MESSAGE_VERSION_THREE):]
- elif bytes.startswith(REQUEST_VERSION_TWO):
- protocol_factory = SmartServerRequestProtocolTwo
- bytes = bytes[len(REQUEST_VERSION_TWO):]
+ if bytes.startswith(protocol.MESSAGE_VERSION_THREE):
+ protocol_factory = protocol.build_server_protocol_three
+ bytes = bytes[len(protocol.MESSAGE_VERSION_THREE):]
+ elif bytes.startswith(protocol.REQUEST_VERSION_TWO):
+ protocol_factory = protocol.SmartServerRequestProtocolTwo
+ bytes = bytes[len(protocol.REQUEST_VERSION_TWO):]
else:
- protocol_factory = SmartServerRequestProtocolOne
+ protocol_factory = protocol.SmartServerRequestProtocolOne
return protocol_factory, bytes
More information about the bazaar-commits
mailing list