[merge] use lazy imports
John Arbash Meinel
john at arbash-meinel.com
Fri Oct 6 07:45:32 BST 2006
The attached patch starts making use of the lazy_import functionality
that got merged into bzr-0.11.
This requires a bit of changes to the code base, since it starts
changing things to import modules, rather than importing members of
modules (which is generally recommended anyway).
So while I haven't change the whole code base, I would like to merge the
little bit that I have already completed, before it gets to be too large
of a change. (It already is getting borderline).
There is still a few places that can be tweaked, like I need to evaluate
ElementTree and ConfigObj, which are our 2 largest startup times right
now (approx 30ms each). I have managed to avoid ElementTree, but
ConfigObj is needed if we want command aliases.
This is the specific impact for the benchmarks:
bench_commit.CommitBenchmark.test_cmd_commit_subprocess OK 383ms/ 509ms
bench_log.LogBenchmark.test_cmd_log_subprocess OK 372ms/ 391ms
bench_rocks.RocksBenchmark.test_rocks OK 283ms/ 285ms
bench_commit.CommitBenchmark.test_cmd_commit_subprocess OK 350ms/ 478ms
bench_log.LogBenchmark.test_cmd_log_subprocess OK 322ms/ 340ms
bench_rocks.RocksBenchmark.test_rocks OK 157ms/ 159ms
So it has a small effect on commit (30ms == 10%), a slightly large one
on log (50ms == 15%), and a rather huge one on 'rocks' (120ms == 50%).
Also the test suite isn't testing with '--no-plugins' so these times are
influenced by what plugins are doing. (And at present, most plugins
aren't very lazy about what they import).
I'm still planning on working more at this, and I think there are quite
a few areas that we can still improve. But I'd like to get this round
merged first.
(by the way, the setup time for cmd_log_subprocess is extra low because
I'm using --cache-dir, not because of the changes I've made).
And I've also run it on my mac, which seems considerably slower:
bench_rocks.RocksBenchmark.test_rocks OK 929ms/ 1145ms
bench_rocks.RocksBenchmark.test_rocks OK 428ms/ 645ms
There also is something to warn about, which is that the lazy objects
are namespace replacers, and not proxy objects. So it isn't allowed to
pass them to other variables, and this includes importing them into
another namespace.
So there are a few places in the code which were doing:
from bzrlib.osutils import rmtree
But now 'rmtree' is lazily imported from 'shutil'. In general, I think
we should avoid directly importing members of modules, and work harder
to just import the modules.
If someone is interested, the lazy import code could also be updated so
that if the module already exists in sys.modules, it just returns it,
rather than creating a replacer object.
I apologize in advance for this being a 3K line patch, and I'll try hard
to submit smaller changes in the future.
John
=:->
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: use_lazy_importer.diff
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20061006/d284f387/attachment.diff
More information about the bazaar
mailing list