laziness
Jelmer Vernooij
jelmer at samba.org
Thu Apr 7 11:32:04 UTC 2011
Over the last couple of months a lot has happened to reduce the amount
of time that Bazaar spends importing Python modules during startup.
Bazaar itself already was doing quite well in this regard, but most of
our tuning had happened without any plugins loaded.
With these changes the startup overhead of "bzr ls" in a small tree
(etckeeper) with bzr 2.3 and bzr.dev on my machine has gone down
from .44 to .20 seconds (best of 5 runs).
= What has happened =
* weave-era formats are now in a separate plugin, and lazy loaded
* hooks can now be installed lazily, without having to import the hook
point
* various additional places in bzrlib now use lazy_import
* bzr dir and control dir implementations can be registered lazily
* working tree formats can be registered lazily
* dwim revspecs can now be registered lazily
* only the current xml serializer implementation is now imported by
default
* knits and knit repository implementations are no longer loaded during
normal operation (MP is up, not merged yet)
* non-metadir branch formats can now be lazily loaded if they need to
be run during the test suite
And of course, a lot of plugins have been updated to use the new
infrastructure available in bzrlib.
= Still to do =
At this point, the only module that could reasonably be avoided but is
still imported is the XML serializer and the related XML module, which
gets pulled in because 2a repositories use XML-based inventory
serialization for their bundles.
= Improving the import overhead of unused plugins =
It's always a good idea to see what other modules your plugin
accidentally pulls in if it's not being used. `bzr FOO --profile-imports
2>imports.log` will write the list of expensive imports (and where they
are first triggered) to imports.log.
`bzr selftest -s bt.test_import_tariff` will test that certain
blacklisted modules are not loaded at startup. If you run it with the
plugin installed, it should still pass.
Where possible, use lazy registration and lazy hook installation. See
bzrlib.commands.plugin_cmds.register_lazy,
bzrlib.hooks.install_lazy_named_hook and Registry.register_lazy for
details.
Cheers,
Jelmer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/bazaar/attachments/20110407/7e7a6fc3/attachment.pgp>
More information about the bazaar
mailing list