bigint: don't allocate in ToPreallocatedBytes
Turns out, it's almost always allocating because we're mostly dealing with small integers while the buffer size is calculated in 8-byte chunks here, so preallocated buffer is always insufficient. name old time/op new time/op delta ToPreallocatedBytes-8 28.5ns ± 7% 19.7ns ± 5% -30.72% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ToPreallocatedBytes-8 16.0B ± 0% 0.0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ToPreallocatedBytes-8 1.00 ± 0% 0.00 -100.00% (p=0.000 n=10+10) Fix StorageItem reuse at the same time. We don't copy when getting values from the storage, but we don when we're putting them, so buffer reuse could corrupt old values.
This commit is contained in:
parent
c3d989ebda
commit
9a06995460
8 changed files with 38 additions and 42 deletions
|
@ -37,7 +37,7 @@ func putConvertibleToDAO(id int32, d *dao.Simple, key []byte, conv stackitem.Con
|
|||
}
|
||||
|
||||
func setIntWithKey(id int32, dao *dao.Simple, key []byte, value int64) {
|
||||
dao.PutStorageItem(id, key, bigint.ToBytes(big.NewInt(value)))
|
||||
dao.PutBigInt(id, key, big.NewInt(value))
|
||||
}
|
||||
|
||||
func getIntWithKey(id int32, dao *dao.Simple, key []byte) int64 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue