[Twisted-Python] Twisted Plugins - Implementation Discussion
Andrew Bennetts
andrew at bemusement.org
Thu Apr 7 07:19:32 MDT 2011
Itamar Turner-Trauring wrote:
[…]
> So, the design has to *not* rely on caching working.
FWIW: this is an achievable goal. I have 32 different bzr plugins
currently installed, and here's the difference they make:
$ time bzr --no-plugins rocks
It sure does!
real 0m0.075s
$ time bzr rocks
It sure does!
real 0m0.119s
So that's about 1.5ms per plugin, on average. With a hot disk cache, at
least…
For comparison, 'twistd --version' takes 116ms, with a dropin.cache and
(I think, although how can I tell?) no plugins installed.
In part, we achieve this via the bzrlib.lazy_import hack, which plugins
can and often do use, and by encouraging plugin authors to put as little
code into their __init__.py files as possible. A typical plugin's
__init__ might do just:
# This is example_plugin/__init__.py
# The actual command implementation is in
# example_plugin/example_commands.py
from bzrlib import commands
commands.plugin_cmds.register_lazy('cmd_class_name', [],
'bzrlib.plugins.example_plugin.example_commands')
Glyph's expressed scepticism that plugin authors and maintainers will
know to keep their __init__.py files cheap to import. Bazaar's
experience is different. Partly that's probably because the Bazaar
community has paid a fair bit of attention to start up time and I
suppose Twisted doesn't have that. But I think also it's partly because
we've provided tools to help people diagnose what/who to blame for bzr
being slow to start, like 'bzr --profile-imports', and even the crude
'time bzr rocks'.
-Andrew.
More information about the Twisted-Python
mailing list