add
[ikiwiki] / doc / tips / optimising_ikiwiki.mdwn
1 Is ikiwiki taking too long to build your wiki? Read on for some common
2 problems that can be avoided to make ikiwiki run quick.
3
4 [[!toc]]
5
6 ## rebuild vs refresh
7
8 Are you building your wiki by running a command like this?
9
10         ikiwiki -setup my.setup
11
12 If so, you're always telling ikiwiki to rebuild the entire site, from
13 scratch. But, ikiwiki is smart, it can incrementally update a site,
14 building only things affected by the changes you make. You just have to let
15 it do so:
16
17         ikiwiki -setup my.setup -refresh
18
19 Ikiwiki automatically uses an incremental refresh like this when handing
20 a web edit, or when run from a [[rcs]] post-commit hook. (If you've
21 configured the hook in the usual way.) Most people who have run into this
22 problem got in the habit of running `ikiwiki -setup my.setup` by hand
23 when their wiki was small, and found it got slower as they added pages.
24
25 ### use the latest version
26
27 If your version of ikiwiki is not [[!verison]], try upgrading. New
28 optimisations are frequently added to ikiwiki, some of them yielding
29 *enormous* speed increases.
30
31 ### expensive inlines
32
33 Do you have an archive page for your blog that shows all posts, 
34 using an inline that looks like this?
35
36         \[[!inline pages="blog/*" show=0]]
37
38 Or maybe you have some tag pages for your blog that show all tagged posts,
39 something like this?
40
41         \[[!inline pages="blog/* and tagged(foo)" show=0]]
42
43 These are expensive, because they have to be updated whenever you modify a
44 matching page. And, if there are a lot of pages, it generates a large html
45 file, which is a lot of work. And also large RSS/Atom files, which is even
46 more work!
47
48 To optimise the inline, consider enabling quick archive mode. Then the
49 inline will only need to be updated when new pages are added; no RSS
50 or Atom feeds will be built, and the generated html file will be much
51 smaller.
52         
53         \[[!inline pages="blog/*" show=0 archive=yes quick=yes]]
54         
55         \[[!inline pages="blog/* and link(tag)" show=0 archive=yes quick=yes]]
56
57 Only downsides: This won't show titles set by the [[!ikiwiki/directive/meta]]
58 directive. And there's no RSS feed for users to use -- but if this page
59 is only for the archives or tag for your blog, users should be subscribing
60 to the blog's main page's RSS feed instead.
61
62 For the main blog page, the inline should only show the latest N posts,
63 which won't be a performance problem:
64
65         \[[!inline pages="blog/*" show=30]]
66
67 ## expensive maps
68
69 Do you have a sitemap type page, that uses a map directive like this?
70
71         \[[!map pages="*" show=title]]
72
73 This is expensive because it has to be updated whenever a page is modified.
74 The resulting html file might get big and expensive to generate as you
75 keep adding pages.
76
77 First, consider removing the "show=title". Then the map will not show page
78 titles set by the [[!ikiwiki/directive/meta]] directive -- but will also
79 only need to be generated when pages are added or removed, not for every
80 page change.
81
82 Consider limiting the map to only show the toplevel pages of your site,
83 like this:
84
85         \[[!map pages="* and !*/*" show=title]]
86
87 Or, alternatively, to drop from the map parts of the site that accumulate
88 lots of pages, like individual blog posts:
89
90         \[[!map pages="* and !blog/*" show=title]]
91
92 ## sidebar issues
93
94 If you enable the [[plugins/sidebar]] plugin, be careful of what you put in
95 your sidebar. Any change that affects what is displayed by the sidebar
96 will require an update of *every* page in the wiki, since all pages include
97 the sidebar.
98
99 Putting an expensive map or inline in the sidebar is the most common cause
100 of problems. At its worst, it can result in any change to any page in the
101 wiki requiring every page to be rebuilt.
102
103 ## avoid htmltidy
104
105 A few plugins do neat stuff, but slowly. Such plugins are tagged
106 [[plugins/type/slow]].
107
108 The worst offender is possibly [[plugins/htmltidy]]. This runs an external
109 `tidy` program on each page that is built, which is necessarily slow. So don't
110 use it unless you really need it; consider using the faster
111 [[plugins/htmlbalance]] instead.
112
113 ## be careful of large linkmaps
114
115 [[plugins/Linkmap]] generates a cool map of links between pages, but
116 it does it using the `graphviz` program. And any changes to links between
117 pages on the map require an update. So, avoid using this to map a large number
118 of pages with frequently changing links. For example, using it to map
119 all the pages on a traditional, highly WikiLinked wiki, is asking for things
120 to be slow. But using it to map a few related pages is probably fine.
121
122 This site's own [[plugins/linkmap]] rarely slows it down, because it
123 only shows the [[index]] page, and the small set of pages that link to it.
124 That is accomplished as follows:
125
126         \[!linkmap pages="index or (backlink(index)"]]
127
128 ## overhead of the search plugin
129
130 Be aware that the [[plugins/search]] plugin has to update the search index
131 whenever any page is changed. This can slow things down somewhat.
132
133 ## scaling to large numbers of pages
134
135 Finally, let's think about how huge number of pages can affect ikiwiki.
136
137 * Every time it's run, ikiwiki has to scan your `srcdir` to find
138   new and changed pages. This is similar in speed to running the `find`
139   command. Obviously, more files will make it take longer.
140
141 * Also, to see what pages match a [[ikiwiki/PageSpec]] like "blog/*", it has
142   to check if every page in the wiki matches. These checks are done quite
143   quickly, but still, lots more pages will make PageSpecs more expensive.
144
145 * The backlinks calculation has to consider every link on every page
146   in the wiki. (In practice, most pages only like to at most a few dozen
147   other pages, so this is not a `O(N^2)`, but closer to `O(N)`.)
148
149 * Ikiwiki also reads and writes an `index` file, which contains information
150   about each page, and so if you have a lot of pages, this file gets large,
151   and more time is spent on it. For a wiki with 2000 pages, this file
152   will run about 500 kb.
153
154 If your wiki will have 100 thousand files in it, you might start seeing
155 the above contribute to ikiwiki running slowly.