]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: improve generated eq algs for structs containing interfaces
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Apr 2020 18:01:38 +0000 (11:01 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Apr 2020 17:19:38 +0000 (17:19 +0000)
commit1cc7be89a94951cbd1b6db669cb5a278e7aea545
tree99ac27797511ff057648e92b750ee7ddb4d7dd47
parentf4e13b83aa771ef84073d783a0eb811d0004ed5e
cmd/compile: improve generated eq algs for structs containing interfaces

type T struct {
    s interface{}
    i int
}

Prior to this change, we generated this equality algorithm for T:

func eqT(p, q *T) bool {
    return p.s.type == q.s.type &&
      runtime.efaceeq(p.s.type, p.s.data, q.s.data) &&
      p.i == q.i
}

This change splits the two halves of the interface equality,
so that we can do the cheap (type) half early and the expensive
(data) half late. We now generate:

func eqT(p, q *T) bool {
    return p.s.type == q.s.type &&
      p.i == q.i &&
      runtime.efaceeq(p.s.type, p.s.data, q.s.data)
}

The generated code tends to be a bit smaller. Examples:

go/ast
.eq."".ForStmt 306 -> 304  (-0.65%)
.eq."".TypeAssertExpr 221 -> 219  (-0.90%)
.eq."".TypeSwitchStmt 228 -> 226  (-0.88%)
.eq."".ParenExpr 150 -> 148  (-1.33%)
.eq."".IndexExpr 221 -> 219  (-0.90%)
.eq."".SwitchStmt 228 -> 226  (-0.88%)
.eq."".RangeStmt 334 -> 332  (-0.60%)

Change-Id: Iec9e24f214ca772416202b9fb9252e625c22380e
Reviewed-on: https://go-review.googlesource.com/c/go/+/230207
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/alg.go