comparison tests/test-walk.t @ 40242:19ed212de2d1

match: optimize matcher when all patterns are of rootfilesin kind Internally at Google, we use narrowspecs with only rootfilesin-kind patterns. Sometimes there are thousands of such patterns (i.e. thousands of tracked directories). In such cases, it can take quite long to build and evaluate the resulting matcher. This patch optimizes matchers that have only patterns of rootfilesin so it instead of creating a regular expression, it matches the given file's directory against the set of directories. In a repo with ~3600 tracked directories, it takes about 1.35 s to build the matcher and 2.7 s to walk the dirstate before this patch. After, it takes 0.04 s to create the matcher and 0.87 s to walk the dirstate. It may be worthwhile to do similar optimizations for e.g. patterns of type "kind:", but that's not a priority for us right now. Differential Revision: https://phab.mercurial-scm.org/D5058
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 13 Oct 2018 00:22:05 -0700
parents 5abc47d4ca6b
children 3984409e144b
comparison
equal deleted inserted replaced
40241:81e4f039a0cd 40242:19ed212de2d1
141 f beans/pinto ../beans/pinto 141 f beans/pinto ../beans/pinto
142 f beans/turtle ../beans/turtle 142 f beans/turtle ../beans/turtle
143 143
144 $ hg debugwalk -v 'rootfilesin:' 144 $ hg debugwalk -v 'rootfilesin:'
145 * matcher: 145 * matcher:
146 <patternmatcher patterns='(?:[^/]+$)'> 146 <patternmatcher patterns="rootfilesin: ['.']">
147 f fennel ../fennel 147 f fennel ../fennel
148 f fenugreek ../fenugreek 148 f fenugreek ../fenugreek
149 f fiddlehead ../fiddlehead 149 f fiddlehead ../fiddlehead
150 $ hg debugwalk -v -I 'rootfilesin:' 150 $ hg debugwalk -v -I 'rootfilesin:'
151 * matcher: 151 * matcher:
152 <includematcher includes='(?:[^/]+$)'> 152 <includematcher includes="rootfilesin: ['.']">
153 f fennel ../fennel 153 f fennel ../fennel
154 f fenugreek ../fenugreek 154 f fenugreek ../fenugreek
155 f fiddlehead ../fiddlehead 155 f fiddlehead ../fiddlehead
156 $ hg debugwalk -v 'rootfilesin:.' 156 $ hg debugwalk -v 'rootfilesin:.'
157 * matcher: 157 * matcher:
158 <patternmatcher patterns='(?:[^/]+$)'> 158 <patternmatcher patterns="rootfilesin: ['.']">
159 f fennel ../fennel 159 f fennel ../fennel
160 f fenugreek ../fenugreek 160 f fenugreek ../fenugreek
161 f fiddlehead ../fiddlehead 161 f fiddlehead ../fiddlehead
162 $ hg debugwalk -v -I 'rootfilesin:.' 162 $ hg debugwalk -v -I 'rootfilesin:.'
163 * matcher: 163 * matcher:
164 <includematcher includes='(?:[^/]+$)'> 164 <includematcher includes="rootfilesin: ['.']">
165 f fennel ../fennel 165 f fennel ../fennel
166 f fenugreek ../fenugreek 166 f fenugreek ../fenugreek
167 f fiddlehead ../fiddlehead 167 f fiddlehead ../fiddlehead
168 $ hg debugwalk -v -X 'rootfilesin:' 168 $ hg debugwalk -v -X 'rootfilesin:'
169 * matcher: 169 * matcher:
170 <differencematcher 170 <differencematcher
171 m1=<alwaysmatcher>, 171 m1=<alwaysmatcher>,
172 m2=<includematcher includes='(?:[^/]+$)'>> 172 m2=<includematcher includes="rootfilesin: ['.']">>
173 f beans/black ../beans/black 173 f beans/black ../beans/black
174 f beans/borlotti ../beans/borlotti 174 f beans/borlotti ../beans/borlotti
175 f beans/kidney ../beans/kidney 175 f beans/kidney ../beans/kidney
176 f beans/navy ../beans/navy 176 f beans/navy ../beans/navy
177 f beans/pinto ../beans/pinto 177 f beans/pinto ../beans/pinto
180 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi 180 f mammals/Procyonidae/coatimundi Procyonidae/coatimundi
181 f mammals/Procyonidae/raccoon Procyonidae/raccoon 181 f mammals/Procyonidae/raccoon Procyonidae/raccoon
182 f mammals/skunk skunk 182 f mammals/skunk skunk
183 $ hg debugwalk -v 'rootfilesin:fennel' 183 $ hg debugwalk -v 'rootfilesin:fennel'
184 * matcher: 184 * matcher:
185 <patternmatcher patterns='(?:fennel/[^/]+$)'> 185 <patternmatcher patterns="rootfilesin: ['fennel']">
186 $ hg debugwalk -v -I 'rootfilesin:fennel' 186 $ hg debugwalk -v -I 'rootfilesin:fennel'
187 * matcher: 187 * matcher:
188 <includematcher includes='(?:fennel/[^/]+$)'> 188 <includematcher includes="rootfilesin: ['fennel']">
189 $ hg debugwalk -v 'rootfilesin:skunk' 189 $ hg debugwalk -v 'rootfilesin:skunk'
190 * matcher: 190 * matcher:
191 <patternmatcher patterns='(?:skunk/[^/]+$)'> 191 <patternmatcher patterns="rootfilesin: ['skunk']">
192 $ hg debugwalk -v -I 'rootfilesin:skunk' 192 $ hg debugwalk -v -I 'rootfilesin:skunk'
193 * matcher: 193 * matcher:
194 <includematcher includes='(?:skunk/[^/]+$)'> 194 <includematcher includes="rootfilesin: ['skunk']">
195 $ hg debugwalk -v 'rootfilesin:beans' 195 $ hg debugwalk -v 'rootfilesin:beans'
196 * matcher: 196 * matcher:
197 <patternmatcher patterns='(?:beans/[^/]+$)'> 197 <patternmatcher patterns="rootfilesin: ['beans']">
198 f beans/black ../beans/black 198 f beans/black ../beans/black
199 f beans/borlotti ../beans/borlotti 199 f beans/borlotti ../beans/borlotti
200 f beans/kidney ../beans/kidney 200 f beans/kidney ../beans/kidney
201 f beans/navy ../beans/navy 201 f beans/navy ../beans/navy
202 f beans/pinto ../beans/pinto 202 f beans/pinto ../beans/pinto
203 f beans/turtle ../beans/turtle 203 f beans/turtle ../beans/turtle
204 $ hg debugwalk -v -I 'rootfilesin:beans' 204 $ hg debugwalk -v -I 'rootfilesin:beans'
205 * matcher: 205 * matcher:
206 <includematcher includes='(?:beans/[^/]+$)'> 206 <includematcher includes="rootfilesin: ['beans']">
207 f beans/black ../beans/black 207 f beans/black ../beans/black
208 f beans/borlotti ../beans/borlotti 208 f beans/borlotti ../beans/borlotti
209 f beans/kidney ../beans/kidney 209 f beans/kidney ../beans/kidney
210 f beans/navy ../beans/navy 210 f beans/navy ../beans/navy
211 f beans/pinto ../beans/pinto 211 f beans/pinto ../beans/pinto
212 f beans/turtle ../beans/turtle 212 f beans/turtle ../beans/turtle
213 $ hg debugwalk -v 'rootfilesin:mammals' 213 $ hg debugwalk -v 'rootfilesin:mammals'
214 * matcher: 214 * matcher:
215 <patternmatcher patterns='(?:mammals/[^/]+$)'> 215 <patternmatcher patterns="rootfilesin: ['mammals']">
216 f mammals/skunk skunk 216 f mammals/skunk skunk
217 $ hg debugwalk -v -I 'rootfilesin:mammals' 217 $ hg debugwalk -v -I 'rootfilesin:mammals'
218 * matcher: 218 * matcher:
219 <includematcher includes='(?:mammals/[^/]+$)'> 219 <includematcher includes="rootfilesin: ['mammals']">
220 f mammals/skunk skunk 220 f mammals/skunk skunk
221 $ hg debugwalk -v 'rootfilesin:mammals/' 221 $ hg debugwalk -v 'rootfilesin:mammals/'
222 * matcher: 222 * matcher:
223 <patternmatcher patterns='(?:mammals/[^/]+$)'> 223 <patternmatcher patterns="rootfilesin: ['mammals']">
224 f mammals/skunk skunk 224 f mammals/skunk skunk
225 $ hg debugwalk -v -I 'rootfilesin:mammals/' 225 $ hg debugwalk -v -I 'rootfilesin:mammals/'
226 * matcher: 226 * matcher:
227 <includematcher includes='(?:mammals/[^/]+$)'> 227 <includematcher includes="rootfilesin: ['mammals']">
228 f mammals/skunk skunk 228 f mammals/skunk skunk
229 $ hg debugwalk -v -X 'rootfilesin:mammals' 229 $ hg debugwalk -v -X 'rootfilesin:mammals'
230 * matcher: 230 * matcher:
231 <differencematcher 231 <differencematcher
232 m1=<alwaysmatcher>, 232 m1=<alwaysmatcher>,
233 m2=<includematcher includes='(?:mammals/[^/]+$)'>> 233 m2=<includematcher includes="rootfilesin: ['mammals']">>
234 f beans/black ../beans/black 234 f beans/black ../beans/black
235 f beans/borlotti ../beans/borlotti 235 f beans/borlotti ../beans/borlotti
236 f beans/kidney ../beans/kidney 236 f beans/kidney ../beans/kidney
237 f beans/navy ../beans/navy 237 f beans/navy ../beans/navy
238 f beans/pinto ../beans/pinto 238 f beans/pinto ../beans/pinto