From 3788c517987348131485fc236f9c2e12a12cf7ba Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 23 Dec 2025 10:38:26 +0530 Subject: [PATCH 1/9] rm bitutil xorbytes helper func --- common/bitutil/bitutil.go | 14 -------- common/bitutil/bitutil_test.go | 65 ---------------------------------- 2 files changed, 79 deletions(-) diff --git a/common/bitutil/bitutil.go b/common/bitutil/bitutil.go index 578da1cf49..99a8c2ee18 100644 --- a/common/bitutil/bitutil.go +++ b/common/bitutil/bitutil.go @@ -8,7 +8,6 @@ package bitutil import ( - "crypto/subtle" "runtime" "unsafe" ) @@ -16,19 +15,6 @@ import ( const wordSize = int(unsafe.Sizeof(uintptr(0))) const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "s390x" -// XORBytes xors the bytes in a and b. The destination is assumed to have enough -// space. Returns the number of bytes xor'd. -// -// If dst does not have length at least n, -// XORBytes panics without writing anything to dst. -// -// dst and x or y may overlap exactly or not at all, -// otherwise XORBytes may panic. -// -// Deprecated: use crypto/subtle.XORBytes -func XORBytes(dst, a, b []byte) int { - return subtle.XORBytes(dst, a, b) -} // ANDBytes ands the bytes in a and b. The destination is assumed to have enough // space. Returns the number of bytes and'd. diff --git a/common/bitutil/bitutil_test.go b/common/bitutil/bitutil_test.go index 1748029794..0cad12bda7 100644 --- a/common/bitutil/bitutil_test.go +++ b/common/bitutil/bitutil_test.go @@ -11,45 +11,6 @@ import ( "testing" ) -// Tests that bitwise XOR works for various alignments. -func TestXOR(t *testing.T) { - for alignP := 0; alignP < 2; alignP++ { - for alignQ := 0; alignQ < 2; alignQ++ { - for alignD := 0; alignD < 2; alignD++ { - p := make([]byte, 1023)[alignP:] - q := make([]byte, 1023)[alignQ:] - - for i := 0; i < len(p); i++ { - p[i] = byte(i) - } - for i := 0; i < len(q); i++ { - q[i] = byte(len(q) - i) - } - d1 := make([]byte, 1023+alignD)[alignD:] - d2 := make([]byte, 1023+alignD)[alignD:] - - XORBytes(d1, p, q) - naiveXOR(d2, p, q) - if !bytes.Equal(d1, d2) { - t.Error("not equal", d1, d2) - } - } - } - } -} - -// naiveXOR xors bytes one by one. -func naiveXOR(dst, a, b []byte) int { - n := len(a) - if len(b) < n { - n = len(b) - } - for i := 0; i < n; i++ { - dst[i] = a[i] ^ b[i] - } - return n -} - // Tests that bitwise AND works for various alignments. func TestAND(t *testing.T) { for alignP := 0; alignP < 2; alignP++ { @@ -124,32 +85,6 @@ func TestTest(t *testing.T) { } } -// Benchmarks the potentially optimized XOR performance. -func BenchmarkFastXOR1KB(b *testing.B) { benchmarkFastXOR(b, 1024) } -func BenchmarkFastXOR2KB(b *testing.B) { benchmarkFastXOR(b, 2048) } -func BenchmarkFastXOR4KB(b *testing.B) { benchmarkFastXOR(b, 4096) } - -func benchmarkFastXOR(b *testing.B, size int) { - p, q := make([]byte, size), make([]byte, size) - - for i := 0; i < b.N; i++ { - XORBytes(p, p, q) - } -} - -// Benchmarks the baseline XOR performance. -func BenchmarkBaseXOR1KB(b *testing.B) { benchmarkBaseXOR(b, 1024) } -func BenchmarkBaseXOR2KB(b *testing.B) { benchmarkBaseXOR(b, 2048) } -func BenchmarkBaseXOR4KB(b *testing.B) { benchmarkBaseXOR(b, 4096) } - -func benchmarkBaseXOR(b *testing.B, size int) { - p, q := make([]byte, size), make([]byte, size) - - for i := 0; i < b.N; i++ { - naiveXOR(p, p, q) - } -} - // Benchmarks the potentially optimized AND performance. func BenchmarkFastAND1KB(b *testing.B) { benchmarkFastAND(b, 1024) } func BenchmarkFastAND2KB(b *testing.B) { benchmarkFastAND(b, 2048) } From 41ebaf0ff2470744b9e9b9967127982bb990da85 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 23 Dec 2025 10:38:53 +0530 Subject: [PATCH 2/9] fix lint --- common/bitutil/bitutil.go | 1 - 1 file changed, 1 deletion(-) diff --git a/common/bitutil/bitutil.go b/common/bitutil/bitutil.go index 99a8c2ee18..b4d44da98f 100644 --- a/common/bitutil/bitutil.go +++ b/common/bitutil/bitutil.go @@ -15,7 +15,6 @@ import ( const wordSize = int(unsafe.Sizeof(uintptr(0))) const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "s390x" - // ANDBytes ands the bytes in a and b. The destination is assumed to have enough // space. Returns the number of bytes and'd. func ANDBytes(dst, a, b []byte) int { From a389dbd80275a937d0ae535248f9fd84fa30a6d0 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 30 Dec 2025 16:25:15 +0530 Subject: [PATCH 3/9] add --- core/vm/memory.go | 19 +++++++++++++------ core/vm/new_bench.txt | 7 +++++++ core/vm/old_bench.txt | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 core/vm/new_bench.txt create mode 100644 core/vm/old_bench.txt diff --git a/core/vm/memory.go b/core/vm/memory.go index 54bc2b2849..a6bde15d6d 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -79,13 +79,20 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { // Resize grows the memory to the requested size. func (m *Memory) Resize(size uint64) { - if uint64(len(m.store)) < size { - if uint64(cap(m.store)) >= size { - m.store = m.store[:size] - } else { - m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...) - } + if size <= uint64(len(m.store)) { + return } + + if size <= uint64(cap(m.store)) { + prevLen := len(m.store) + m.store = m.store[:size] + clear(m.store[prevLen:]) + return + } + + store := make([]byte, size) + copy(store, m.store) + m.store = store } // GetCopy returns offset + size as a new slice diff --git a/core/vm/new_bench.txt b/core/vm/new_bench.txt new file mode 100644 index 0000000000..1cb4014e25 --- /dev/null +++ b/core/vm/new_bench.txt @@ -0,0 +1,7 @@ +goos: linux +goarch: amd64 +pkg: github.com/ethereum/go-ethereum/core/vm +cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz +BenchmarkResize-8 876326 89800 ns/op 442142 B/op 1 allocs/op +BenchmarkResize-8 signal: interrupt +FAIL github.com/ethereum/go-ethereum/core/vm 154.281s diff --git a/core/vm/old_bench.txt b/core/vm/old_bench.txt new file mode 100644 index 0000000000..53c0eff049 --- /dev/null +++ b/core/vm/old_bench.txt @@ -0,0 +1,16 @@ +goos: linux +goarch: amd64 +pkg: github.com/ethereum/go-ethereum/core/vm +cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz +BenchmarkResize-8 513681400 4.756 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 747650196 2.313 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 907757728 1.302 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 906696679 1.356 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 832139062 2.823 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 943258486 2.120 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 1000000000 1.619 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 982619973 1.388 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 761129438 1.351 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 943591894 1.643 ns/op 6 B/op 0 allocs/op +PASS +ok github.com/ethereum/go-ethereum/core/vm 37.469s From bc1c5a75988dc426680eaf5ac61b3870fb5c1543 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 30 Dec 2025 17:23:12 +0530 Subject: [PATCH 4/9] revert add --- core/vm/memory.go | 19 ++++++------------- core/vm/new_bench.txt | 7 ------- core/vm/old_bench.txt | 16 ---------------- 3 files changed, 6 insertions(+), 36 deletions(-) delete mode 100644 core/vm/new_bench.txt delete mode 100644 core/vm/old_bench.txt diff --git a/core/vm/memory.go b/core/vm/memory.go index a6bde15d6d..54bc2b2849 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -79,20 +79,13 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { // Resize grows the memory to the requested size. func (m *Memory) Resize(size uint64) { - if size <= uint64(len(m.store)) { - return + if uint64(len(m.store)) < size { + if uint64(cap(m.store)) >= size { + m.store = m.store[:size] + } else { + m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...) + } } - - if size <= uint64(cap(m.store)) { - prevLen := len(m.store) - m.store = m.store[:size] - clear(m.store[prevLen:]) - return - } - - store := make([]byte, size) - copy(store, m.store) - m.store = store } // GetCopy returns offset + size as a new slice diff --git a/core/vm/new_bench.txt b/core/vm/new_bench.txt deleted file mode 100644 index 1cb4014e25..0000000000 --- a/core/vm/new_bench.txt +++ /dev/null @@ -1,7 +0,0 @@ -goos: linux -goarch: amd64 -pkg: github.com/ethereum/go-ethereum/core/vm -cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz -BenchmarkResize-8 876326 89800 ns/op 442142 B/op 1 allocs/op -BenchmarkResize-8 signal: interrupt -FAIL github.com/ethereum/go-ethereum/core/vm 154.281s diff --git a/core/vm/old_bench.txt b/core/vm/old_bench.txt deleted file mode 100644 index 53c0eff049..0000000000 --- a/core/vm/old_bench.txt +++ /dev/null @@ -1,16 +0,0 @@ -goos: linux -goarch: amd64 -pkg: github.com/ethereum/go-ethereum/core/vm -cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz -BenchmarkResize-8 513681400 4.756 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 747650196 2.313 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 907757728 1.302 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 906696679 1.356 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 832139062 2.823 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 943258486 2.120 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 1000000000 1.619 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 982619973 1.388 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 761129438 1.351 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 943591894 1.643 ns/op 6 B/op 0 allocs/op -PASS -ok github.com/ethereum/go-ethereum/core/vm 37.469s From e5c96ca45c3cbe8e11546416fdc913381c01521a Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 13 Jan 2026 10:43:18 +0530 Subject: [PATCH 5/9] Revert "revert add" This reverts commit da1d57e95d6354cefdbfc593a84888502331fcd2. --- core/vm/memory.go | 19 +++++++++++++------ core/vm/new_bench.txt | 7 +++++++ core/vm/old_bench.txt | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 core/vm/new_bench.txt create mode 100644 core/vm/old_bench.txt diff --git a/core/vm/memory.go b/core/vm/memory.go index 54bc2b2849..a6bde15d6d 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -79,13 +79,20 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { // Resize grows the memory to the requested size. func (m *Memory) Resize(size uint64) { - if uint64(len(m.store)) < size { - if uint64(cap(m.store)) >= size { - m.store = m.store[:size] - } else { - m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...) - } + if size <= uint64(len(m.store)) { + return } + + if size <= uint64(cap(m.store)) { + prevLen := len(m.store) + m.store = m.store[:size] + clear(m.store[prevLen:]) + return + } + + store := make([]byte, size) + copy(store, m.store) + m.store = store } // GetCopy returns offset + size as a new slice diff --git a/core/vm/new_bench.txt b/core/vm/new_bench.txt new file mode 100644 index 0000000000..1cb4014e25 --- /dev/null +++ b/core/vm/new_bench.txt @@ -0,0 +1,7 @@ +goos: linux +goarch: amd64 +pkg: github.com/ethereum/go-ethereum/core/vm +cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz +BenchmarkResize-8 876326 89800 ns/op 442142 B/op 1 allocs/op +BenchmarkResize-8 signal: interrupt +FAIL github.com/ethereum/go-ethereum/core/vm 154.281s diff --git a/core/vm/old_bench.txt b/core/vm/old_bench.txt new file mode 100644 index 0000000000..53c0eff049 --- /dev/null +++ b/core/vm/old_bench.txt @@ -0,0 +1,16 @@ +goos: linux +goarch: amd64 +pkg: github.com/ethereum/go-ethereum/core/vm +cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz +BenchmarkResize-8 513681400 4.756 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 747650196 2.313 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 907757728 1.302 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 906696679 1.356 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 832139062 2.823 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 943258486 2.120 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 1000000000 1.619 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 982619973 1.388 ns/op 5 B/op 0 allocs/op +BenchmarkResize-8 761129438 1.351 ns/op 6 B/op 0 allocs/op +BenchmarkResize-8 943591894 1.643 ns/op 6 B/op 0 allocs/op +PASS +ok github.com/ethereum/go-ethereum/core/vm 37.469s From 2eaf312084d7eccc13be4a704c6b387a09dea0c8 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 13 Jan 2026 10:43:24 +0530 Subject: [PATCH 6/9] Revert "add" This reverts commit c31e755c0583b9e7c2c6e0b2916d1735d559c274. --- core/vm/memory.go | 19 ++++++------------- core/vm/new_bench.txt | 7 ------- core/vm/old_bench.txt | 16 ---------------- 3 files changed, 6 insertions(+), 36 deletions(-) delete mode 100644 core/vm/new_bench.txt delete mode 100644 core/vm/old_bench.txt diff --git a/core/vm/memory.go b/core/vm/memory.go index a6bde15d6d..54bc2b2849 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -79,20 +79,13 @@ func (m *Memory) Set32(offset uint64, val *uint256.Int) { // Resize grows the memory to the requested size. func (m *Memory) Resize(size uint64) { - if size <= uint64(len(m.store)) { - return + if uint64(len(m.store)) < size { + if uint64(cap(m.store)) >= size { + m.store = m.store[:size] + } else { + m.store = append(m.store, make([]byte, size-uint64(len(m.store)))...) + } } - - if size <= uint64(cap(m.store)) { - prevLen := len(m.store) - m.store = m.store[:size] - clear(m.store[prevLen:]) - return - } - - store := make([]byte, size) - copy(store, m.store) - m.store = store } // GetCopy returns offset + size as a new slice diff --git a/core/vm/new_bench.txt b/core/vm/new_bench.txt deleted file mode 100644 index 1cb4014e25..0000000000 --- a/core/vm/new_bench.txt +++ /dev/null @@ -1,7 +0,0 @@ -goos: linux -goarch: amd64 -pkg: github.com/ethereum/go-ethereum/core/vm -cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz -BenchmarkResize-8 876326 89800 ns/op 442142 B/op 1 allocs/op -BenchmarkResize-8 signal: interrupt -FAIL github.com/ethereum/go-ethereum/core/vm 154.281s diff --git a/core/vm/old_bench.txt b/core/vm/old_bench.txt deleted file mode 100644 index 53c0eff049..0000000000 --- a/core/vm/old_bench.txt +++ /dev/null @@ -1,16 +0,0 @@ -goos: linux -goarch: amd64 -pkg: github.com/ethereum/go-ethereum/core/vm -cpu: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz -BenchmarkResize-8 513681400 4.756 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 747650196 2.313 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 907757728 1.302 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 906696679 1.356 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 832139062 2.823 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 943258486 2.120 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 1000000000 1.619 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 982619973 1.388 ns/op 5 B/op 0 allocs/op -BenchmarkResize-8 761129438 1.351 ns/op 6 B/op 0 allocs/op -BenchmarkResize-8 943591894 1.643 ns/op 6 B/op 0 allocs/op -PASS -ok github.com/ethereum/go-ethereum/core/vm 37.469s From 1d268e86b51a8dc3fc6774a2516d19428b7d8eaa Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 13 Jan 2026 10:43:25 +0530 Subject: [PATCH 7/9] Revert "fix lint" This reverts commit 4bf0f253514a8512d6c5e2938bc943974fc0df86. --- common/bitutil/bitutil.go | 1 + 1 file changed, 1 insertion(+) diff --git a/common/bitutil/bitutil.go b/common/bitutil/bitutil.go index b4d44da98f..99a8c2ee18 100644 --- a/common/bitutil/bitutil.go +++ b/common/bitutil/bitutil.go @@ -15,6 +15,7 @@ import ( const wordSize = int(unsafe.Sizeof(uintptr(0))) const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "s390x" + // ANDBytes ands the bytes in a and b. The destination is assumed to have enough // space. Returns the number of bytes and'd. func ANDBytes(dst, a, b []byte) int { From b80ffe98a5451eb040d320550414d0888930a8d9 Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Tue, 13 Jan 2026 10:43:26 +0530 Subject: [PATCH 8/9] Revert "rm bitutil xorbytes helper func" This reverts commit 121c43075e7ae11272a39d4bdcd635ff05c48085. --- common/bitutil/bitutil.go | 14 ++++++++ common/bitutil/bitutil_test.go | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/common/bitutil/bitutil.go b/common/bitutil/bitutil.go index 99a8c2ee18..578da1cf49 100644 --- a/common/bitutil/bitutil.go +++ b/common/bitutil/bitutil.go @@ -8,6 +8,7 @@ package bitutil import ( + "crypto/subtle" "runtime" "unsafe" ) @@ -15,6 +16,19 @@ import ( const wordSize = int(unsafe.Sizeof(uintptr(0))) const supportsUnaligned = runtime.GOARCH == "386" || runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" || runtime.GOARCH == "s390x" +// XORBytes xors the bytes in a and b. The destination is assumed to have enough +// space. Returns the number of bytes xor'd. +// +// If dst does not have length at least n, +// XORBytes panics without writing anything to dst. +// +// dst and x or y may overlap exactly or not at all, +// otherwise XORBytes may panic. +// +// Deprecated: use crypto/subtle.XORBytes +func XORBytes(dst, a, b []byte) int { + return subtle.XORBytes(dst, a, b) +} // ANDBytes ands the bytes in a and b. The destination is assumed to have enough // space. Returns the number of bytes and'd. diff --git a/common/bitutil/bitutil_test.go b/common/bitutil/bitutil_test.go index 0cad12bda7..1748029794 100644 --- a/common/bitutil/bitutil_test.go +++ b/common/bitutil/bitutil_test.go @@ -11,6 +11,45 @@ import ( "testing" ) +// Tests that bitwise XOR works for various alignments. +func TestXOR(t *testing.T) { + for alignP := 0; alignP < 2; alignP++ { + for alignQ := 0; alignQ < 2; alignQ++ { + for alignD := 0; alignD < 2; alignD++ { + p := make([]byte, 1023)[alignP:] + q := make([]byte, 1023)[alignQ:] + + for i := 0; i < len(p); i++ { + p[i] = byte(i) + } + for i := 0; i < len(q); i++ { + q[i] = byte(len(q) - i) + } + d1 := make([]byte, 1023+alignD)[alignD:] + d2 := make([]byte, 1023+alignD)[alignD:] + + XORBytes(d1, p, q) + naiveXOR(d2, p, q) + if !bytes.Equal(d1, d2) { + t.Error("not equal", d1, d2) + } + } + } + } +} + +// naiveXOR xors bytes one by one. +func naiveXOR(dst, a, b []byte) int { + n := len(a) + if len(b) < n { + n = len(b) + } + for i := 0; i < n; i++ { + dst[i] = a[i] ^ b[i] + } + return n +} + // Tests that bitwise AND works for various alignments. func TestAND(t *testing.T) { for alignP := 0; alignP < 2; alignP++ { @@ -85,6 +124,32 @@ func TestTest(t *testing.T) { } } +// Benchmarks the potentially optimized XOR performance. +func BenchmarkFastXOR1KB(b *testing.B) { benchmarkFastXOR(b, 1024) } +func BenchmarkFastXOR2KB(b *testing.B) { benchmarkFastXOR(b, 2048) } +func BenchmarkFastXOR4KB(b *testing.B) { benchmarkFastXOR(b, 4096) } + +func benchmarkFastXOR(b *testing.B, size int) { + p, q := make([]byte, size), make([]byte, size) + + for i := 0; i < b.N; i++ { + XORBytes(p, p, q) + } +} + +// Benchmarks the baseline XOR performance. +func BenchmarkBaseXOR1KB(b *testing.B) { benchmarkBaseXOR(b, 1024) } +func BenchmarkBaseXOR2KB(b *testing.B) { benchmarkBaseXOR(b, 2048) } +func BenchmarkBaseXOR4KB(b *testing.B) { benchmarkBaseXOR(b, 4096) } + +func benchmarkBaseXOR(b *testing.B, size int) { + p, q := make([]byte, size), make([]byte, size) + + for i := 0; i < b.N; i++ { + naiveXOR(p, p, q) + } +} + // Benchmarks the potentially optimized AND performance. func BenchmarkFastAND1KB(b *testing.B) { benchmarkFastAND(b, 1024) } func BenchmarkFastAND2KB(b *testing.B) { benchmarkFastAND(b, 2048) } From 70a52dc4fb7fcbd861d287a7fcbbffdb153b996f Mon Sep 17 00:00:00 2001 From: Sahil-4555 Date: Thu, 15 Jan 2026 08:52:45 +0530 Subject: [PATCH 9/9] rpc: close ws handshake response body on error --- rpc/websocket.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/websocket.go b/rpc/websocket.go index 543ff617ba..ad81cf0b1a 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -249,6 +249,9 @@ func newClientTransportWS(endpoint string, cfg *clientConfig) (reconnectFunc, er } conn, resp, err := dialer.DialContext(ctx, dialURL, header) if err != nil { + if resp != nil { + resp.Body.Close() + } hErr := wsHandshakeError{err: err} if resp != nil { hErr.status = resp.Status