I have benchmarked the pagename() call this avoids taking up to 2 seconds
for a loadindex in a large wiki. The total loadindex for that wiki was
6.46s, so this is a significant improvment.
Even on a smaller site, this reduces the refresh time from 1.69 to 1.52
seconds.
The only breakage risk here is that pagename() can change the page name
it calculates due to setup changes. But in the case of a setup change, the
whole site is rebuilt. So the cached page name is not used in that
case.
sub loadindex () {
%oldrenderedfiles=%pagectime=();
sub loadindex () {
%oldrenderedfiles=%pagectime=();
- if (! $config{rebuild}) {
+ my $rebuild=$config{rebuild};
+ if (! $rebuild) {
%pagesources=%pagemtime=%oldlinks=%links=%depends=
%destsources=%renderedfiles=%pagecase=%pagestate=
%depends_simple=%typedlinks=%oldtypedlinks=();
%pagesources=%pagemtime=%oldlinks=%links=%depends=
%destsources=%renderedfiles=%pagecase=%pagestate=
%depends_simple=%typedlinks=%oldtypedlinks=();
foreach my $src (keys %$pages) {
my $d=$pages->{$src};
foreach my $src (keys %$pages) {
my $d=$pages->{$src};
- my $page=pagename($src);
+ my $page;
+ if (exists $d->{page} && ! $rebuild) {
+ $page=$d->{page};
+ }
+ else {
+ $page=pagename($src);
+ }
$pagectime{$page}=$d->{ctime};
$pagesources{$page}=$src;
$pagectime{$page}=$d->{ctime};
$pagesources{$page}=$src;
- if (! $config{rebuild}) {
$pagemtime{$page}=$d->{mtime};
$renderedfiles{$page}=$d->{dest};
if (exists $d->{links} && ref $d->{links}) {
$pagemtime{$page}=$d->{mtime};
$renderedfiles{$page}=$d->{dest};
if (exists $d->{links} && ref $d->{links}) {
my $src=$pagesources{$page};
$index{page}{$src}={
my $src=$pagesources{$page};
$index{page}{$src}={
ctime => $pagectime{$page},
mtime => $pagemtime{$page},
dest => $renderedfiles{$page},
ctime => $pagectime{$page},
mtime => $pagemtime{$page},
dest => $renderedfiles{$page},
* Fixed unncessary tight loop hash copy in saveindex where a pointer
can be used instead. Can speed up refreshes by nearly 50% in some
circumstances.
* Fixed unncessary tight loop hash copy in saveindex where a pointer
can be used instead. Can speed up refreshes by nearly 50% in some
circumstances.
+ * Optmised loadindex by caching the page name in the index.
-- Joey Hess <joeyh@debian.org> Thu, 05 Sep 2013 10:01:10 -0400
-- Joey Hess <joeyh@debian.org> Thu, 05 Sep 2013 10:01:10 -0400