Skip to content

Commit

Permalink
internal/core/adt: don't allocate when asserting in Environment.up
Browse files Browse the repository at this point in the history
Assertf takes remaining formatting arguments as ..any,
and since the arguments we pass here are two integers,
they escape when a pointer to them is needed to fit into an interface.
Environment.up is called often, so this resulted in about 4.6%
of the total allocated objects in `cue vet -c=false ./...`.

The small amount of added debug info doesn't seem worth a 2% CPU cost.
We could likely write the assertion in a way that doesn't escape values,
but that also doesn't seem worth the hassle right now.

              │    old     │                new                │
              │   sec/op   │   sec/op    vs base               │
    CueVetAll   1.968 ± 1%   1.929 ± 1%  -1.97% (p=0.000 n=10)

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I9334b91ed41f36d7e755504d37d49a9430c4a174
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194375
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Marcel van Lohuizen <[email protected]>
  • Loading branch information
mvdan committed May 7, 2024
1 parent c445c7d commit 9ecd7a0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type cacheKey struct {
func (e *Environment) up(ctx *OpContext, count int32) *Environment {
for i := int32(0); i < count; i++ {
e = e.Up
ctx.Assertf(ctx.Pos(), e.Vertex != nil, "Environment.up encountered a nil vertex at step %d out of %d", i+1, count)
ctx.Assertf(ctx.Pos(), e.Vertex != nil, "Environment.up encountered a nil vertex")
}
return e
}
Expand Down

0 comments on commit 9ecd7a0

Please sign in to comment.