]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move pinned object out of inner loop for benchmarks
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 23 May 2023 21:02:36 +0000 (21:02 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 24 May 2023 16:22:30 +0000 (16:22 +0000)
In theory by allocating new objects every time, the benchmark is
including the performance of allocating new pinner bits for a span. In
practice however, most of the time each span already does have pinner
bits allocated (it's still a rare operation).

We can get a better sense of the raw cost of pinning an object (minus
pinner bits allocation) by moving the object allocation out of the inner
loop.

Change-Id: I2869fa6c3f353b726fe8440d2e6b7f89902f9364
Reviewed-on: https://go-review.googlesource.com/c/go/+/497620
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>

src/runtime/pinner_test.go

index 1caebcb265967b5ba8928d6977afc86b15be2171..88ead7c946301b068ee842079ac80555c2ee2bd6 100644 (file)
@@ -420,25 +420,27 @@ func BenchmarkPinnerPinUnpinBatchTiny(b *testing.B) {
 }
 
 func BenchmarkPinnerPinUnpin(b *testing.B) {
+       p := new(obj)
        for n := 0; n < b.N; n++ {
                var pinner runtime.Pinner
-               pinner.Pin(new(obj))
+               pinner.Pin(p)
                pinner.Unpin()
        }
 }
 
 func BenchmarkPinnerPinUnpinTiny(b *testing.B) {
+       p := new(bool)
        for n := 0; n < b.N; n++ {
                var pinner runtime.Pinner
-               pinner.Pin(new(bool))
+               pinner.Pin(p)
                pinner.Unpin()
        }
 }
 
 func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
+       p := new(obj)
        for n := 0; n < b.N; n++ {
                var pinner runtime.Pinner
-               p := new(obj)
                pinner.Pin(p)
                pinner.Pin(p)
                pinner.Unpin()
@@ -447,9 +449,10 @@ func BenchmarkPinnerPinUnpinDouble(b *testing.B) {
 
 func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
        b.RunParallel(func(pb *testing.PB) {
+               p := new(obj)
                for pb.Next() {
                        var pinner runtime.Pinner
-                       pinner.Pin(new(obj))
+                       pinner.Pin(p)
                        pinner.Unpin()
                }
        })
@@ -457,9 +460,10 @@ func BenchmarkPinnerPinUnpinParallel(b *testing.B) {
 
 func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
        b.RunParallel(func(pb *testing.PB) {
+               p := new(bool)
                for pb.Next() {
                        var pinner runtime.Pinner
-                       pinner.Pin(new(bool))
+                       pinner.Pin(p)
                        pinner.Unpin()
                }
        })
@@ -467,9 +471,9 @@ func BenchmarkPinnerPinUnpinParallelTiny(b *testing.B) {
 
 func BenchmarkPinnerPinUnpinParallelDouble(b *testing.B) {
        b.RunParallel(func(pb *testing.PB) {
+               p := new(obj)
                for pb.Next() {
                        var pinner runtime.Pinner
-                       p := new(obj)
                        pinner.Pin(p)
                        pinner.Pin(p)
                        pinner.Unpin()