(no commit message)
[ikiwiki] / doc / recentchanges / change_171c429f829aac53cb449e3bb574d2a1669e025e._change
1 [[!meta author="""http://kerravonsen.dreamwidth.org/"""]]
2
3 [[!meta authorurl="""http://kerravonsen.dreamwidth.org/"""]]
4
5 [[!meta title="""change to todo/Improving_the_efficiency_of_match__95__glob on ikiwiki"""]]
6
7 [[!meta permalink="http://ikiwiki.info/recentchanges/#change-171c429f829aac53cb449e3bb574d2a1669e025e"]]
8
9 <div id="change-171c429f829aac53cb449e3bb574d2a1669e025e" class="metadata">
10 <span class="desc"><br />Changed pages:</span>
11 <span class="pagelinks">
12
13 <a href="http://git.ikiwiki.info/?p=ikiwiki;a=blobdiff;f=doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn;h=8f70f1dde4bbe7fd7b66807c36e6f4d7fd0b08b0;hp=0000000000000000000000000000000000000000;hb=171c429f829aac53cb449e3bb574d2a1669e025e;hpb=9c8f86ee9c59035c9462d2c69c7b89d0c9dbc3c2" title="diff" rel="nofollow">[[diff|wikiicons/diff.png]]</a><a href="http://ikiwiki.info/ikiwiki.cgi?page=todo%2FImproving_the_efficiency_of_match__95__glob&amp;do=goto" rel="nofollow">todo/Improving the efficiency of match&#95;glob</a>
14
15
16 </span>
17 <span class="desc"><br />Changed by:</span>
18 <span class="committer">
19
20 <a href="http://kerravonsen.dreamwidth.org/" rel="nofollow">kerravonsen [dreamwidth.org]</a>
21
22 </span>
23 <span class="desc"><br />Commit type:</span>
24 <span class="committype">web</span>
25 <span class="desc"><br />Date:</span>
26 <span class="changedate"><span class="relativedate" title="Tue, 09 Nov 2010 20:53:10 -0400">20:53:10 11/09/10</span></span>
27 <span class="desc"><br /></span>
28 </div>
29
30 <span class="revert">
31 <a href="http://ikiwiki.info/ikiwiki.cgi?rev=171c429f829aac53cb449e3bb574d2a1669e025e&amp;do=revert" title="revert" rel="nofollow">[[revert|wikiicons/revert.png]]</a>
32 </span>
33
34 <div class="changelog">
35
36
37 make match_glob faster - patch!<br />
38
39
40 </div>
41
42 <div class="diff">
43 <pre>
44 diff --git a/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn b/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn
45 new file mode 100644
46 index 0000000..8f70f1d
47 --- /dev/null
48 +++ b/doc/todo/Improving_the_efficiency_of_match__95__glob.mdwn
49 @@ -0,0 +1,39 @@
50 +I&#39;ve been profiling my IkiWiki to try to improve speed (with many pages makes speed even more important) and I&#39;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.
51 +
52 +Here&#39;s my patch - please consider it! -- &#91;&#91;KathrynAndersen&#93;&#93;
53 +
54 +--------------------------------------------------------------
55 +&lt;pre&gt;
56 +diff --git a/IkiWiki.pm b/IkiWiki.pm
57 +index 08a3d78..c187b98 100644
58 +--- a/IkiWiki.pm
59 ++++ b/IkiWiki.pm
60 +@@ -2482,6 +2482,8 @@ sub derel ($$) {
61 +       return $path;
62 + }
63
64 ++my %glob_cache;
65 ++
66 + sub match_glob ($$;@) {
67 +       my $page=shift;
68 +       my $glob=shift;
69 +@@ -2489,8 +2491,15 @@ sub match_glob ($$;@) {
70 +       
71 +       $glob=derel($glob, $params{location});
72
73 +-      my $regexp=IkiWiki::glob2re($glob);
74 +-      if ($page=~/^$regexp$/i) {
75 ++      # Instead of converting the glob to a regex every time,
76 ++      # cache the compiled regex to save time.
77 ++      if (!exists $glob_cache{$glob}
78 ++          or !defined $glob_cache{$glob})
79 ++      {
80 ++          my $re=IkiWiki::glob2re($glob);
81 ++          $glob_cache{$glob} = qr/^$re$/i;
82 ++      }
83 ++      if ($page =~ $glob_cache{$glob}) {
84 +               if (! IkiWiki::isinternal($page) || $params{internal}) {
85 +                       return IkiWiki::SuccessReason-&gt;new(&quot;$glob matches $page&quot;);
86 +               }
87 +&lt;/pre&gt;
88 +--------------------------------------------------------------
89
90 </pre>
91 </div>
92
93 <!-- 171c429f829aac53cb449e3bb574d2a1669e025e -->