Skip to content

Reuse encoding buffer#40

Merged
arashpayan merged 2 commits intomainfrom
reuse_encoding_buffer
Mar 12, 2026
Merged

Reuse encoding buffer#40
arashpayan merged 2 commits intomainfrom
reuse_encoding_buffer

Conversation

@rakitzis
Copy link
Copy Markdown
Collaborator

@rakitzis rakitzis commented Mar 12, 2026

Reuse request encoding buffer across sends
conn.encodeBuf is retained to encode outgoing request packets.
conn.m is held for the entire write sequence so serialized
access is guaranteed.

This shaves an allocation.

Before:

BenchmarkRoundTrip/Plain/1KB-10         	  329035	      3706 ns/op	 276.34 MB/s	    1627 B/op	       6 allocs/op
BenchmarkRoundTrip/Plain/64KB-10        	  128247	      9145 ns/op	7166.00 MB/s	   74212 B/op	       6 allocs/op
BenchmarkRoundTrip/Plain/1MB-10         	   22280	     53276 ns/op	19682.07 MB/s	 1057258 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/1KB-10     	  241368	      5028 ns/op	 203.67 MB/s	    3554 B/op	       7 allocs/op
BenchmarkRoundTrip/Encrypted/64KB-10    	   39223	     30939 ns/op	2118.22 MB/s	  164387 B/op	       7 allocs/op
BenchmarkRoundTrip/Encrypted/1MB-10     	    3859	    306180 ns/op	3424.71 MB/s	 2377340 B/op	       7 allocs/op

After:

BenchmarkRoundTrip/Plain/1KB-10         	  286184	      3561 ns/op	 287.58 MB/s	    1500 B/op	       5 allocs/op
BenchmarkRoundTrip/Plain/64KB-10        	  129012	      9022 ns/op	7264.18 MB/s	   74084 B/op	       5 allocs/op
BenchmarkRoundTrip/Plain/1MB-10         	   22854	     52175 ns/op	20097.33 MB/s	 1057221 B/op	       5 allocs/op
BenchmarkRoundTrip/Encrypted/1KB-10     	  240336	      4948 ns/op	 206.95 MB/s	    3426 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/64KB-10    	   39441	     30362 ns/op	2158.48 MB/s	  164319 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/1MB-10     	    3963	    307307 ns/op	3412.14 MB/s	 2376662 B/op	       6 allocs/op

rakitzis and others added 2 commits March 12, 2026 14:20
conn.encodeBuf is retained to encode outgoing request packets.
conn.m is held for the entire write sequence so serialized
access is guaranteed.

This shaves an allocation.

Before:
```
BenchmarkRoundTrip/Plain/1KB-10         	  329035	      3706 ns/op	 276.34 MB/s	    1627 B/op	       6 allocs/op
BenchmarkRoundTrip/Plain/64KB-10        	  128247	      9145 ns/op	7166.00 MB/s	   74212 B/op	       6 allocs/op
BenchmarkRoundTrip/Plain/1MB-10         	   22280	     53276 ns/op	19682.07 MB/s	 1057258 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/1KB-10     	  241368	      5028 ns/op	 203.67 MB/s	    3554 B/op	       7 allocs/op
BenchmarkRoundTrip/Encrypted/64KB-10    	   39223	     30939 ns/op	2118.22 MB/s	  164387 B/op	       7 allocs/op
BenchmarkRoundTrip/Encrypted/1MB-10     	    3859	    306180 ns/op	3424.71 MB/s	 2377340 B/op	       7 allocs/op
```

After:

```
BenchmarkRoundTrip/Plain/1KB-10         	  286184	      3561 ns/op	 287.58 MB/s	    1500 B/op	       5 allocs/op
BenchmarkRoundTrip/Plain/64KB-10        	  129012	      9022 ns/op	7264.18 MB/s	   74084 B/op	       5 allocs/op
BenchmarkRoundTrip/Plain/1MB-10         	   22854	     52175 ns/op	20097.33 MB/s	 1057221 B/op	       5 allocs/op
BenchmarkRoundTrip/Encrypted/1KB-10     	  240336	      4948 ns/op	 206.95 MB/s	    3426 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/64KB-10    	   39441	     30362 ns/op	2158.48 MB/s	  164319 B/op	       6 allocs/op
BenchmarkRoundTrip/Encrypted/1MB-10     	    3963	    307307 ns/op	3412.14 MB/s	 2376662 B/op	       6 allocs/op
```

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This is a somewhat defensive commit but several fields in the
SMB packet header rely on the implicit zeroing provided
by Go's make() builtin. We zero the memory here defensively
since e.g., nonce sizes may change from one packet to the next.
@arashpayan arashpayan merged commit baa2e30 into main Mar 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants