]> sipb.mit.edu Git - ikiwiki.git/commitdiff
crazy optimisation to work around slow markdown
authorJoey Hess <joey@kodama.kitenet.net>
Fri, 21 Mar 2008 08:48:26 +0000 (04:48 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Fri, 21 Mar 2008 08:48:26 +0000 (04:48 -0400)
Markdown is slow. Especially if it has to process an enormous page. The
most common enormous page is currently the recentchanges page, which gets
processed a lot, and contains very little actual markdown. Most of it is a
big <div>, which markdown skips ... slowly.

This is a rather sick optimisation to work around markdown's speed issues.
Now inline inserts a small, dummy div, allows markdown to quickly render
the actual page content, then replaces the dummy with the actual inlined
pages later.

Results: Rendering just a recentchanges page, with diffs included, dropped
from 4.5 seconds to 2.7 seconds on my laptop. Building the entire wiki
dropped from 46.6 seconds to 39.5 seconds.

(It would be better if inline were a *post*-processor directive.)

IkiWiki/Plugin/inline.pm
debian/changelog

index c7107d6645504c7939c37df2b5ab8caebcabb445..0002371c1373d504686ceea1b3ab756e2319ebae 100644 (file)
@@ -10,6 +10,7 @@ use URI;
 
 my %knownfeeds;
 my %page_numfeeds;
+my @inline;
 
 sub import { #{{{
        hook(type => "getopt", id => "inline", call => \&getopt);
@@ -19,6 +20,7 @@ sub import { #{{{
                call => \&IkiWiki::preprocess_inline);
        hook(type => "pagetemplate", id => "inline",
                call => \&IkiWiki::pagetemplate_inline);
+       hook(type => "format", id => "inline", call => \&format);
        # Hook to change to do pinging since it's called late.
        # This ensures each page only pings once and prevents slow
        # pings interrupting page builds.
@@ -51,6 +53,15 @@ sub checkconfig () { #{{{
        }
 } #}}}
 
+sub format (@) { #{{{
+        my %params=@_;
+
+       # Fill in the inline content generated earlier. This is actually an
+       # optimisation.
+       $params{content}=~s!<div class="inline" id="([^"]+)"></div>!$inline[$1]!g;
+       return $params{content};
+} #}}}
+
 sub sessioncgi () { #{{{
        my $q=shift;
        my $session=shift;
@@ -304,7 +315,9 @@ sub preprocess_inline (@) { #{{{
                }
        }
        
-       return $ret;
+       return $ret if $raw;
+       push @inline, $ret;
+       return "<div class=\"inline\" id=\"$#inline\"></div>\n\n";
 } #}}}
 
 sub pagetemplate_inline (@) { #{{{
index 81a5d4a1d14fec41487da997906280f9dee4fc78..c92cf86ed8edbac91cbc716f1fdec4a7bde3b340 100644 (file)
@@ -56,6 +56,7 @@ ikiwiki (2.41) UNRELEASED; urgency=low
     (Old files will be automatically converted.)
   * Close meta tag for redir properly.
   * smiley: Detect smileys inside pre and code tags, and do not expand.
+  * inline: Crazy optimisation to work around slow markdown.
 
  -- martin f. krafft <madduck@debian.org>  Sun, 02 Mar 2008 17:46:38 +0100