From 04ecdf60453846e0ab397f1a36497bb3b268f2bb Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Tue, 6 Jul 2021 21:24:21 +0500 Subject: [PATCH] Preallocate memory when deriving address from key This makes src/address.AddrForKey preallocate 32 bytes before starting the address derivation. As benches in syg_go show, reallocating temp takes 20% of the function runtime. --- src/address/address.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/address/address.go b/src/address/address.go index 7add23a..0e2400e 100644 --- a/src/address/address.go +++ b/src/address/address.go @@ -64,7 +64,7 @@ func AddrForKey(publicKey ed25519.PublicKey) *Address { buf[idx] = ^buf[idx] } var addr Address - var temp []byte + var temp = make([]byte, 0, 32) done := false ones := byte(0) bits := byte(0)