this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/core/dep: use a new visitor.marked map when recursing

Otherwise the recursing visit call will remember all the marked
nodes from the parent's visit state, causing a significant amount
of repeated work when Config.Dynamic is true without changing the result.

This is because visitor.dynamic uses the presence of leaf conjuncts
in the "marked" map to decide whether to visit a vertex,
so if the marked map is kept when recursing, the nested visitor
ends up visiting way too many vertices and repeating work.

The test case added in the previous commit now runs in about 80ms
rather than in about 7s, and the stats are much lower as well.

Fixes #2559.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I77f9a6c4ec4165eb49c685cc5656ebafce5ed9e6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198566
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+13 -10
+3
internal/core/dep/dep.go
··· 129 129 func (d *Dependency) Recurse() { 130 130 savedAll := d.visitor.all 131 131 savedTop := d.visitor.top 132 + savedMarked := d.visitor.marked 132 133 d.visitor.all = d.visitor.recurse 133 134 d.visitor.top = true 135 + d.visitor.marked = nil 134 136 135 137 d.visitor.visitReusingVisitor(d.Node, false) 136 138 137 139 d.visitor.all = savedAll 138 140 d.visitor.top = savedTop 141 + d.visitor.marked = savedMarked 139 142 } 140 143 141 144 // Import returns the import reference or nil if the reference was within
+10 -10
tools/flow/testdata/issue2559.txtar
··· 60 60 } 61 61 -- out/run/t1/stats -- 62 62 Leaks: 0 63 - Freed: 262168 64 - Reused: 262148 63 + Freed: 25792 64 + Reused: 25772 65 65 Allocs: 20 66 66 Retain: 352 67 67 68 - Unifications: 187362 69 - Conjuncts: 902602 70 - Disjuncts: 262432 68 + Unifications: 18522 69 + Conjuncts: 76898 70 + Disjuncts: 26056 71 71 -- out/run/stats/totals -- 72 72 Leaks: 0 73 - Freed: 262168 74 - Reused: 262148 73 + Freed: 25792 74 + Reused: 25772 75 75 Allocs: 20 76 76 Retain: 352 77 77 78 - Unifications: 187362 79 - Conjuncts: 902602 80 - Disjuncts: 262432 78 + Unifications: 18522 79 + Conjuncts: 76898 80 + Disjuncts: 26056 81 81 -- out/run/t2 -- 82 82 graph TD 83 83 t0("root.prepare [Terminated]")