diff options
author | http://kerravonsen.dreamwidth.org/ <http://kerravonsen.dreamwidth.org/@web> | 2010-11-10 00:53:10 +0000 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-11-10 00:53:10 +0000 |
commit | 171c429f829aac53cb449e3bb574d2a1669e025e (patch) | |
tree | 095c3019adc17dc2f611353e75ae4d5e014c4445 /doc/todo | |
parent | 9c8f86ee9c59035c9462d2c69c7b89d0c9dbc3c2 (diff) | |
download | ikiwiki-171c429f829aac53cb449e3bb574d2a1669e025e.tar ikiwiki-171c429f829aac53cb449e3bb574d2a1669e025e.tar.gz |
make match_glob faster - patch!
Diffstat (limited to 'doc/todo')
-rw-r--r-- | doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn b/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn new file mode 100644 index 000000000..8f70f1dde --- /dev/null +++ b/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn @@ -0,0 +1,39 @@ +I've been profiling my IkiWiki to try to improve speed (with many pages makes speed even more important) and I've written a patch to improve the speed of match_glob. This matcher is a good one to improve the speed of, because it gets called so many times. + +Here's my patch - please consider it! -- [[KathrynAndersen]] + +-------------------------------------------------------------- +<pre> +diff --git a/IkiWiki.pm b/IkiWiki.pm +index 08a3d78..c187b98 100644 +--- a/IkiWiki.pm ++++ b/IkiWiki.pm +@@ -2482,6 +2482,8 @@ sub derel ($$) { + return $path; + } + ++my %glob_cache; ++ + sub match_glob ($$;@) { + my $page=shift; + my $glob=shift; +@@ -2489,8 +2491,15 @@ sub match_glob ($$;@) { + + $glob=derel($glob, $params{location}); + +- my $regexp=IkiWiki::glob2re($glob); +- if ($page=~/^$regexp$/i) { ++ # Instead of converting the glob to a regex every time, ++ # cache the compiled regex to save time. ++ if (!exists $glob_cache{$glob} ++ or !defined $glob_cache{$glob}) ++ { ++ my $re=IkiWiki::glob2re($glob); ++ $glob_cache{$glob} = qr/^$re$/i; ++ } ++ if ($page =~ $glob_cache{$glob}) { + if (! IkiWiki::isinternal($page) || $params{internal}) { + return IkiWiki::SuccessReason->new("$glob matches $page"); + } +</pre> +-------------------------------------------------------------- |