[dokuwiki] xhtml processing optimisation.

  • From: Michiel Kamermans <pomax@xxxxxxxxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Thu, 01 Oct 2009 11:25:10 -0700

Hi all,

I'm running a few plugins on a dokuwiki now which all function as xhtml postprocessor, but running the entire page several times through several plugins does slow things down significantly. One option of course is to combine the plugins into a single monster plugin, to speed things up, but that would be a bit drastic.

Has anyone every run to this problem before and solved it in a more civilised manner? Perhaps throwing a few ideas around on how to streamline multiple plugins operating on the same data would yield some usable interesting idea. I was thinking perhaps a new event that is thrown for every finalised xhtml line, so that plugins that can do their work in-place would be able to modify the lines as they're generated. Another option might be globally accessible xhtml postprocessing container with processing objects that can be added to it, with users defining a new xhtml_postprocessing_plugin extension, which in its constructor adds their custom line processing object to the processing container, with an optional method binding that gets passed the entire xhtml array once its done, should full processing be required.

in code:

------------------------------

// set up some time during dokuwiki init:

$XHTML_LINE_PROCESSORS = array();

// user code residing in for instance wiki/lib/plugins/[plugin name]/processor.php:

class line_processor extends dokuwiki_xhtml_postprocessing_plugin
{
   // custom processor class
   class myprocessor extends dokuwiki_line_processor {
      // override on parent function
function process(&$line) { /* do in-place single line processing here */ }
   }

// called by dokuwiki to obtain the processor for sticking in the global var, which then calls
   // $XHTML_LINE_PROCESSORS[] = $return_value;
   //
function get_line_processor() { return new dokuwiki_line_processor_extension(); }

   // leads to accessing method of this plugin performing the call
// $controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'AFTER', $this, $return_value);
   //
function get_full_processing_function_name() { return "_process_all_data"; }

// function that would currently be found in an action plugin bound to the postprocess event. function _process_all_data(&$event) { /* do full xhtml processing here */ }
}

// and finally, during xhtml generation when a line's finished:

[...]
foreach($plaindata as $textline) {
$line = do_some_stuff_to($textline);
foreach($XHTML_LINE_PROCESSORS as $processor) { $processor->process($line); }
$xhtml[] = $line; }
// pass $xhtml to whatever plugins registered for RENDERER_CONTENT_POSTPROCESS
[...]

------------------------------

I'd imagine the second solution to be a decent amount faster than a new per-line event.

- Mike "Pomax" Kamermans
nihongoresources.com
dokuwiki: grammar.nihongoresources.com
--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: