What changed, and why it matters
This commit only adds a new performance benchmark test for the brontide encrypted connection code. It does not change any production code, fix any bug, or alter behavior. There is no security relevance.
No action needed; this is a test-only benchmark addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds BenchmarkWriteMessage to brontide/bench_test.go. It establishes a test noise connection, constructs a MaxUint16-byte payload, and repeatedly calls noise.WriteMessage and noise.Flush to io.Discard while measuring allocations and CPU time. No production logic is modified.
Changed components
brontide/bench_test.goInspect captured patch +45 / −0
diff --git a/brontide/bench_test.go b/brontide/bench_test.go
index 214d61f..0605c54 100644
--- a/brontide/bench_test.go
+++ b/brontide/bench_test.go
@@ -2,6 +2,7 @@ package brontide
import (
"bytes"
+ "io"
"math"
"math/rand"
"testing"
@@ -63,3 +64,47 @@ func BenchmarkReadHeaderAndBody(t *testing.B) {
}
require.NoError(t, benchErr)
}
+
+// BenchmarkWriteMessage benchmarks the performance of writing a maximum-sized
+// message and flushing it to an io.Discard to measure the allocation and CPU
+// overhead of the encryption and writing logic.
+func BenchmarkWriteMessage(b *testing.B) {
+ localConn, remoteConn, err := establishTestConnection(b)
+ require.NoError(b, err, "unable to establish test connection: %v", err)
+
+ noiseLocalConn, ok := localConn.(*Conn)
+ require.True(b, ok, "expected *Conn type for localConn")
+
+ // Create the largest possible message we can write (MaxUint16 bytes).
+ // This is the maximum message size allowed by the protocol.
+ const maxMsgSize = math.MaxUint16
+ largeMsg := bytes.Repeat([]byte("a"), maxMsgSize)
+
+ // Use io.Discard to simulate writing to a network connection that
+ // continuously accepts data without needing resets.
+ discard := io.Discard
+
+ b.ReportAllocs()
+ b.ResetTimer()
+
+ for i := 0; i < b.N; i++ {
+ // Write our massive message, then call flush to actually write
+ // the encrypted message This simulates a full write operation
+ // to a network.
+ err := noiseLocalConn.noise.WriteMessage(largeMsg)
+ if err != nil {
+ b.Fatalf("WriteMessage failed: %v", err)
+ }
+ _, err = noiseLocalConn.noise.Flush(discard)
+ if err != nil {
+ b.Fatalf("Flush failed: %v", err)
+ }
+ }
+
+ // We'll make sure to clean up the connections at the end of the
+ // benchmark.
+ b.Cleanup(func() {
+ localConn.Close()
+ remoteConn.Close()
+ })
+}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.