this repo has no description
0
fork

Configure Feed

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

internal/core/adt: reuse vertex maps in overlayContext

We don't need to use a pool of maps; each new map in an overlayContext
is passed as-is to an overlayFrame in the OpContext.overlays stack,
so once we "pop" an overlayFrame its map can later be reused.

│ old │ new │
│ B/op │ B/op vs base │
Roman 6.673Gi ± ∞ ¹ 6.508Gi ± ∞ ¹ -2.46% (p=1.000 n=1)

│ old │ new │
│ allocs/op │ allocs/op vs base │
Roman 71.43M ± ∞ ¹ 69.59M ± ∞ ¹ -2.58% (p=1.000 n=1)

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I25f284ffb2da7712b8a22c8b1f8b30376c992fe4
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1226958
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+13 -5
+13 -5
internal/core/adt/overlay.go
··· 42 42 // could get by with only copying arcs to that are modified in the copy. 43 43 44 44 func newOverlayContext(ctx *OpContext) *overlayContext { 45 + // Reuse the map from the overlays stack if one exists at this depth. 46 + var m vertexMap 47 + if i := len(ctx.overlays); i < cap(ctx.overlays) { 48 + m = ctx.overlays[:cap(ctx.overlays)][i].vertexMap 49 + } 50 + if m == nil { 51 + m = make(map[*Vertex]*Vertex) 52 + } 45 53 return &overlayContext{ 46 - ctx: ctx, 47 - 48 - // TODO(perf): take a map from a pool of maps and reuse. 49 - vertexMap: make(map[*Vertex]*Vertex), 54 + ctx: ctx, 55 + vertexMap: m, 50 56 } 51 57 } 52 58 ··· 98 104 } 99 105 100 106 func (c *OpContext) popOverlay() { 101 - c.overlays = c.overlays[:len(c.overlays)-1] 107 + i := len(c.overlays) - 1 108 + clear(c.overlays[i].vertexMap) 109 + c.overlays = c.overlays[:i] 102 110 } 103 111 104 112 func (c *OpContext) deref(v *Vertex) *Vertex {