Commit 1b5e0f6
committed
perf: hoist loop-invariant graph conversions out of the monomorphism search
generate_all_subgraphs rebuilt the template's nx.DiGraph, and re-read
T.all_nodes(), inside the inner loop -- once for each of the 2^|nodes| node
subsets, though both are the same every time. `.subgraph()` returns a
read-only view, so one conversion serves them all. On an 11-node template
that is 2036 conversions instead of 1.
TemplateMatcher._generate_mappings had the same shape and the more expensive
version of it: every candidate subgraph built a _VF2SemanticMatcher, and each
of those converted the whole *building* graph again. It now converts once and
passes the result down through a new optional T_digraph argument; the matcher
only reads the graph, so sharing one instance is safe.
Output is unchanged -- with a fixed PYTHONHASHSEED, generate_all_subgraphs
yields a byte-identical sequence before and after. Matching a 4-node
guideline36 template against a 6k-triple model goes from 7.66s to 6.36s; the
remainder is the VF2 search itself, which this does not touch.1 parent 64ae7a0 commit 1b5e0f6
1 file changed
Lines changed: 32 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
196 | 201 | | |
197 | 202 | | |
198 | | - | |
199 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
200 | 214 | | |
201 | 215 | | |
202 | 216 | | |
| |||
222 | 236 | | |
223 | 237 | | |
224 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
225 | 244 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
230 | 248 | | |
231 | 249 | | |
232 | 250 | | |
| |||
279 | 297 | | |
280 | 298 | | |
281 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
282 | 304 | | |
283 | 305 | | |
284 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
285 | 310 | | |
286 | 311 | | |
287 | 312 | | |
| |||
0 commit comments