1 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.
3 Here's my patch - please consider it! -- [[KathrynAndersen]]
5 > It seems to me as though changing `glob2re` to return qr/$re/, and calling
6 > `memoize(glob2re)` next to the other memoize calls, would be a less
7 > verbose way to do this? --[[smcv]]
9 >> I think so, yeah. Anyway, do you have any benchmark results handy,
10 >> Kathryn? --[[Joey]]
13 >>> Also, would it make more sense for glob2re to return qr/^$re$/i rather than qr/$re/? Everything that uses glob2re seems to use
15 >>> rather than /$re/ so I think that would make sense.
16 >>> -- [[KathrynAndersen]]
18 --------------------------------------------------------------
19 Benchmarks done with Devel::Profile on the same testbed IkiWiki setup. I'm just showing the start of the profile output, since that's what's relevant.
23 time elapsed (wall): 27.4173
24 time running program: 22.5909 (82.40%)
25 time profiling (est.): 4.8264 (17.60%)
26 number of calls: 1314729
27 number of exceptions: 65
29 %Time Sec. #calls sec/call F name
30 11.05 2.4969 62333 0.000040 IkiWiki::PageSpec::match_glob
31 4.10 0.9261 679 0.001364 Text::Balanced::_match_tagged
32 2.72 0.6139 59812 0.000010 IkiWiki::SuccessReason::merge_influences
37 time elapsed (wall): 26.1843
38 time running program: 21.5673 (82.37%)
39 time profiling (est.): 4.6170 (17.63%)
40 number of calls: 1252433
41 number of exceptions: 65
43 %Time Sec. #calls sec/call F name
44 7.66 1.6521 62333 0.000027 IkiWiki::PageSpec::match_glob
45 4.33 0.9336 679 0.001375 Text::Balanced::_match_tagged
46 2.81 0.6057 59812 0.000010 IkiWiki::SuccessReason::merge_influences
49 Note that the seconds per call for match_glob in the "after" case has gone down by about a third.
53 --------------------------------------------------------------
55 diff --git a/IkiWiki.pm b/IkiWiki.pm
56 index 08a3d78..c187b98 100644
59 @@ -2482,6 +2482,8 @@ sub derel ($$) {
65 sub match_glob ($$;@) {
68 @@ -2489,8 +2491,15 @@ sub match_glob ($$;@) {
70 $glob=derel($glob, $params{location});
72 - my $regexp=IkiWiki::glob2re($glob);
73 - if ($page=~/^$regexp$/i) {
74 + # Instead of converting the glob to a regex every time,
75 + # cache the compiled regex to save time.
76 + if (!exists $glob_cache{$glob}
77 + or !defined $glob_cache{$glob})
79 + my $re=IkiWiki::glob2re($glob);
80 + $glob_cache{$glob} = qr/^$re$/i;
82 + if ($page =~ $glob_cache{$glob}) {
83 if (! IkiWiki::isinternal($page) || $params{internal}) {
84 return IkiWiki::SuccessReason->new("$glob matches $page");
87 --------------------------------------------------------------