internal/core/adt: deduplicate Vertex.Structs by StructLit
This avoids some duplicate entries with the same struct literal
but a different Environment or CloseInfo.
Those two fields of StructInfo are only used by tools/trim;
the export and toposort packages only use StructLit for their ordering.
Deduplicating with the three fields makes no difference to tools/trim,
so it's best if we deduplicate by StructLit. To avoid minor changes
to ordering in the toposort and export tests, we also track how many
times each StructLit had repeated calls to Vertex.AddStruct.
The toposort algorithm needs this to apply the proper weight to a
StructLit in its dependency analysis.
Note that we remove the result parameter from AddStruct,
which was never used and just made the logic harder to follow.
The allocation savings here are tiny but not the point of this change.
The big advantage is that we can further simplify the Vertex.Structs
structure once this change has been applied,
reducing the allocations past the cost of the added Repeats field.
│ old │ new │
│ B/op │ B/op vs base │
Roman 6.452Gi ± ∞ ¹ 6.471Gi ± ∞ ¹ +0.29% (p=1.000 n=1)
│ old │ new │
│ allocs/op │ allocs/op vs base │
Roman 68.00M ± ∞ ¹ 67.97M ± ∞ ¹ -0.04% (p=1.000 n=1)
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I6f36792b68d91e0b2edc42768367700f69e99e3d
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1226964
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>