Merge lp:~mbp/bzr/lazy-commands into lp:bzr

Proposed by Martin Pool
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mbp/bzr/lazy-commands
Merge into: lp:bzr
Diff against target: 134 lines (+61/-9)
5 files modified
.bzrignore (+1/-0)
NEWS (+34/-0)
bzrlib/builtins.py (+18/-5)
bzrlib/commands.py (+1/-4)
bzrlib/tests/test_import_tariff.py (+7/-0)
To merge this branch: bzr merge lp:~mbp/bzr/lazy-commands
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+22590@code.launchpad.net

Commit message

(mbp) lazy-load some more commands

Description of the change

This makes some other commands not inline within builtins.py be lazy-loaded.

John previously raised in <https://code.edge.launchpad.net/~mbp/bzr/lazy-commands/+merge/21910> the issue of testing handling of aliases etc for lazy commands. I had a look in test_commands and there is already some coverage of that, enough that I don't feel like looking for trouble.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

This does seem to slightly cut the time to run 'bzr st' with cold caches in a bzr tree on my machine 'grace' from about 1.772-1.892s down to 1.568-1.716s.

Revision history for this message
Andrew Bennetts (spiv) wrote :

Looks good! Possibly worth a NEWS entry.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2009-10-07 15:48:32 +0000
3+++ .bzrignore 2010-04-01 08:23:23 +0000
4@@ -67,3 +67,4 @@
5 bzrlib/_*.so
6 bzrlib/_*.pyd
7 ./.ccache
8+.testrepository
9
10=== modified file 'NEWS'
11--- NEWS 2010-04-01 00:40:31 +0000
12+++ NEWS 2010-04-01 08:23:23 +0000
13@@ -5,6 +5,40 @@
14 .. contents:: List of Releases
15 :depth: 1
16
17+bzr 2.2b2
18+#########
19+
20+:2.2b2: NOT RELEASED YET
21+
22+Compatibility Breaks
23+********************
24+
25+New Features
26+************
27+
28+Bug Fixes
29+*********
30+
31+Improvements
32+************
33+
34+* Less code is loaded at startup. (Cold-cache start time is about 10-20%
35+ less.)
36+ (Martin Pool, #553017)
37+
38+Documentation
39+*************
40+
41+API Changes
42+***********
43+
44+Internals
45+*********
46+
47+Testing
48+*******
49+
50+
51 bzr 2.2.0b1
52 ###########
53
54
55=== modified file 'bzrlib/builtins.py'
56--- bzrlib/builtins.py 2010-03-29 06:37:23 +0000
57+++ bzrlib/builtins.py 2010-04-01 08:23:23 +0000
58@@ -60,7 +60,11 @@
59 from bzrlib.workingtree import WorkingTree
60 """)
61
62-from bzrlib.commands import Command, display_command
63+from bzrlib.commands import (
64+ Command,
65+ builtin_command_registry,
66+ display_command,
67+ )
68 from bzrlib.option import (
69 ListOption,
70 Option,
71@@ -4062,6 +4066,7 @@
72
73 def run(self, file_list=None, merge_type=None, show_base=False,
74 reprocess=False):
75+ from bzrlib.conflicts import restore
76 if merge_type is None:
77 merge_type = _mod_merge.Merge3Merger
78 tree, file_list = tree_files(file_list)
79@@ -5975,7 +5980,15 @@
80 self.outf.write('%s %s\n' % (path, location))
81
82
83-from bzrlib.cmd_version_info import cmd_version_info
84-from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
85-from bzrlib.foreign import cmd_dpush
86-from bzrlib.sign_my_commits import cmd_sign_my_commits
87+def _register_lazy_builtins():
88+ # register lazy builtins from other modules; called at startup and should
89+ # be only called once.
90+ for (name, aliases, module_name) in [
91+ ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
92+ ('cmd_dpush', [], 'bzrlib.foreign'),
93+ ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
94+ ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
95+ ('cmd_conflicts', [], 'bzrlib.conflicts'),
96+ ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
97+ ]:
98+ builtin_command_registry.register_lazy(name, aliases, module_name)
99
100=== modified file 'bzrlib/commands.py'
101--- bzrlib/commands.py 2010-03-25 06:52:38 +0000
102+++ bzrlib/commands.py 2010-04-01 08:23:23 +0000
103@@ -182,10 +182,7 @@
104 import bzrlib.builtins
105 for cmd_class in _scan_module_for_commands(bzrlib.builtins).values():
106 builtin_command_registry.register(cmd_class)
107- # lazy builtins
108- builtin_command_registry.register_lazy('cmd_bundle_info',
109- [],
110- 'bzrlib.bundle.commands')
111+ bzrlib.builtins._register_lazy_builtins()
112
113
114 def _scan_module_for_commands(module):
115
116=== modified file 'bzrlib/tests/test_import_tariff.py'
117--- bzrlib/tests/test_import_tariff.py 2010-03-23 06:03:14 +0000
118+++ bzrlib/tests/test_import_tariff.py 2010-04-01 08:23:23 +0000
119@@ -91,8 +91,15 @@
120 self.make_branch_and_tree('.')
121 self.run_command_check_imports(['st'], [
122 'bzrlib.bundle.commands',
123+ 'bzrlib.cmd_version_info',
124+ 'bzrlib.foreign',
125 'bzrlib.remote',
126+ 'bzrlib.sign_my_commits',
127 'bzrlib.smart',
128 'smtplib',
129 'tarfile',
130 ])
131+ # TODO: similar test for repository-only operations, checking we avoid
132+ # loading wt-specific stuff
133+ #
134+ # See https://bugs.edge.launchpad.net/bzr/+bug/553017