Spurred on by the first comment by an actual user of my plugin today, I tracked down one of the major bottlenecks for external ikiwiki plugins. My fix might not be the most elegant, but it works so far.
The problem
Ikiwiki plugins work by calling a function named hook
which lets
them tell the ikiwiki compiler that they implement a certain
subroutine. Whenever that subroutine needs to be called, the
ikiwiki compiler calls run_hooks
, and that runs all the registered
functions.
For most of these hooked functions (htmlize
is the only exception
I can think of), all of the registered functions are called,
regardless of file type. This is normally not a problem, because
the plugin can check the type of content that it is given and only
operate on the types of content that it knows anything about.
For external plugins, however, there is a problem. Ikiwiki
communicates with external plugins via xml-rpc on stdin
and
stdout
. Every function call that it makes involves writing the
function's parameters on stdout
. When there is a file type that
is unknown to the external plugin, all that effort (I/O is the main
time sink I think, but the content must also be encoded correctly
for xml-rpc) is wasted.
The solution
I have added a parameter named "exclusive" to the optional arguments
that are accepted by the hook
function. When this argument exists
(and is true), the registered function is only run when the type of
file is the same as the type of file that the plugin accepts. So
far, it only works with the scan
and linkify
hooks, which were
the main areas that slowed my plugin down. However, it is quite
simple to get it to work with other hooks as well.