summaryrefslogtreecommitdiff
path: root/IkiWiki.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-05-05 23:40:09 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-05-06 00:27:24 -0400
commit2a7721febd6cac1af5e7f4b4949ffe066c62c837 (patch)
treec0e488da71e36ce1842e2553e2cf683e49d15676 /IkiWiki.pm
parent1c7c9e95f227a3ff7906c000ec15bb163edc463f (diff)
Avoid %links accumulating duplicates. (For TOVA)
This is sorta an optimisation, and sorta a bug fix. In one test case I have available, it can speed a page build up from 3 minutes to 3 seconds. The root of the problem is that $links{$page} contains arrays of links, rather than hashes of links. And when a link is found, it is just pushed onto the array, without checking for dups. Now, the array is emptied before scanning a page, so there should not be a lot of opportunity for lots of duplicate links to pile up in it. But, in some cases, they can, and if there are hundreds of duplicate links in the array, then scanning it for matching links, as match_link and some other code does, becomes much more expensive than it needs to be. Perhaps the real right fix would be to change the data structure to a hash. But, the list of links is never accessed like that, you always want to iterate through it. I also looked at deduping the list in saveindex, but that does a lot of unnecessary work, and doesn't completly solve the problem. So, finally, I decided to add an add_link function that handles deduping, and make ikiwiki-transition remove the old dup links.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r--IkiWiki.pm12
1 files changed, 10 insertions, 2 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index e260fffea..e6efe1889 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -21,12 +21,12 @@ our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
pagespec_match_list bestlink htmllink readfile writefile
pagetype srcfile pagename displaytime will_render gettext urlto
targetpage add_underlay pagetitle titlepage linkpage
- newpagefile inject
+ newpagefile inject add_link
%config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources);
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
-our $installdir=''; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
+our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE
# Optimisation.
use Memoize;
@@ -1757,6 +1757,14 @@ sub inject {
use warnings;
}
+sub add_link ($$) {
+ my $page=shift;
+ my $link=shift;
+
+ push @{$links{$page}}, $link
+ unless grep { $_ eq $link } @{$links{$page}};
+}
+
sub pagespec_merge ($$) {
my $a=shift;
my $b=shift;