Roman Khimov
1e0c70ecb0
Merge pull request #2117 from nspcc-dev/io-grow
...
Some io package improvements
2021-08-10 09:57:31 +03:00
Evgeniy Stratonikov
73e4040628
mpt: use BinWriter.Grow()
instead of custom buffer
...
Also add benchmarks.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-10 09:34:05 +03:00
Evgeniy Stratonikov
c74de9a579
network: preallocate buffer for message
...
```
name old time/op new time/op delta
MessageBytes-8 740ns ± 0% 684ns ± 2% -7.58% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
MessageBytes-8 1.39kB ± 0% 1.20kB ± 0% -13.79% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
MessageBytes-8 11.0 ± 0% 10.0 ± 0% -9.09% (p=0.000 n=10+10)
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-10 09:33:52 +03:00
Roman Khimov
cf13f30dbf
Merge pull request #2112 from nspcc-dev/gas-balance
...
Improve NEP17 transfer serialization
2021-08-09 12:18:46 +03:00
Evgeniy Stratonikov
dacf025dd9
io: add Grow
to BinWriter
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 12:05:31 +03:00
Evgeniy Stratonikov
c69670c85b
io: use a single slice for numbers
...
Slice takes 24 bytes of memory, while we really need only 9.
```
name old time/op new time/op delta
Transaction_Bytes-8 667ns ±17% 583ns ± 6% -12.50% (p=0.000 n=10+10)
GetVarSize-8 283ns ±11% 189ns ± 5% -33.37% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
Transaction_Bytes-8 1.01kB ± 0% 0.88kB ± 0% -12.70% (p=0.000 n=10+10)
GetVarSize-8 184B ± 0% 56B ± 0% -69.57% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
Transaction_Bytes-8 7.00 ± 0% 6.00 ± 0% -14.29% (p=0.000 n=10+10)
GetVarSize-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=10+10)
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 12:04:28 +03:00
Evgeniy Stratonikov
620295efe3
transaction: add benchmark for transaction serialization
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 12:01:38 +03:00
Evgeniy Stratonikov
23adb1e2fc
state: optimize NEP17TransferLog.Append
...
Do not allocate a separate buffer for the transfer.
```
name old time/op new time/op delta
NEP17TransferLog_Append-8 58.8µs ± 3% 32.1µs ± 1% -45.40% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
NEP17TransferLog_Append-8 118kB ± 1% 44kB ± 3% -63.00% (p=0.000 n=9+10)
name old allocs/op new allocs/op delta
NEP17TransferLog_Append-8 901 ± 1% 513 ± 3% -43.08% (p=0.000 n=9+8)
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 11:09:49 +03:00
Evgeniy Stratonikov
403a4b75de
state/test: add benchmark for NEP17TransferLog.Append
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 11:09:49 +03:00
Evgeniy Stratonikov
b210a34b1e
state: optimize NEP17Balance
deserialization
...
```
BenchmarkNEP17BalanceFromBytes/stackitem-8 2402318 503.3 ns/op 208 B/op 10 allocs/op
BenchmarkNEP17BalanceFromBytes/from_bytes-8 7623139 160.7 ns/op 72 B/op 3 allocs/op
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 11:09:49 +03:00
Evgeniy Stratonikov
3218b74ea5
state: optimize NEP17Balance
serialization
...
Put to slice directly and allow to provide pre-allocated buffer.
```
BenchmarkNEP17BalanceBytes/stackitem-8 1712475 673.4 ns/op 448 B/op 9 allocs/op
BenchmarkNEP17BalanceBytes/bytes-8 13422715 75.80 ns/op 32 B/op 2 allocs/op
BenchmarkNEP17BalanceBytes/bytes,_prealloc-8 25990371 46.46 ns/op 16 B/op 1 allocs/op
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-09 11:09:06 +03:00
Roman Khimov
b989504d74
Merge pull request #2108 from nspcc-dev/optimize-mpt
...
Some allocation optimizations
2021-08-06 14:51:10 +03:00
Roman Khimov
1355b0e974
README: it's GitHub
2021-08-06 14:50:06 +03:00
Roman Khimov
badbedfa65
CHANGELOG: release 0.97.1
2021-08-06 14:36:37 +03:00
Roman Khimov
2329e25d1e
Merge pull request #2100 from nspcc-dev/cli-compiler-groups
...
cli/smartcontract: provide manifest groups on deploy
2021-08-06 12:58:43 +03:00
Evgeniy Stratonikov
653ecbe50e
docs/compiler.md: document manifest groups
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:05:36 +03:00
Evgeniy Stratonikov
adcae12331
cli/smartcontract: reuse read functions in contractDeploy
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:05:36 +03:00
Evgeniy Stratonikov
868198a36e
cli/smartcontract: add manifest add-group
command
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:05:32 +03:00
Evgeniy Stratonikov
6fe2ace43b
cli/smartcontract: refactor contract deploy a bit
...
Provide cosigners explicitly during deploy and don't read wallet twice.
This is needed because manifest validation requires valid sender address.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:05:32 +03:00
Evgeniy Stratonikov
f83395e897
cli/test: move test wallet path to constant
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:05:32 +03:00
Evgeniy Stratonikov
bd2b1a0521
mpt: add Size
method to trie nodes
...
Knowing serialized size of the node is useful for
preallocating byte-slice in advance.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:01:16 +03:00
Evgeniy Stratonikov
db80ef28df
mpt: move empty hash node in a separate type
...
We use them quite frequently (consider children for a new branch
node) and it is better to get rid of unneeded allocations.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 12:01:16 +03:00
Evgeniy Stratonikov
f02d8b4ec4
stackitem: serialize integers to the pre-allocated slice
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 11:59:24 +03:00
Evgeniy Stratonikov
291a29af1e
*: do not use WriteArray
for frequently used items
...
`WriteArray` involves reflection, it makes sense to optimize
serialization of transactions and application logs which are serialized
constantly. Adding case in a type switch in `WriteArray` is not an
option because we don't want new dependencies for `io` package.
```
name old time/op new time/op delta
AppExecResult_EncodeBinary-8 852ns ± 3% 656ns ± 2% -22.94% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
AppExecResult_EncodeBinary-8 448B ± 0% 376B ± 0% -16.07% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
AppExecResult_EncodeBinary-8 7.00 ± 0% 5.00 ± 0% -28.57% (p=0.000 n=10+10)
```
```
name old time/op new time/op delta
Transaction_Bytes-8 1.29µs ± 3% 0.76µs ± 5% -41.52% (p=0.000 n=9+10)
name old alloc/op new alloc/op delta
Transaction_Bytes-8 1.21kB ± 0% 1.01kB ± 0% -16.56% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
Transaction_Bytes-8 12.0 ± 0% 7.0 ± 0% -41.67% (p=0.000 n=10+10)
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 11:59:20 +03:00
Roman Khimov
95e1f5f77b
Merge pull request #2113 from nspcc-dev/optimize-witness-hashing
...
core: don't recalculate witness script hash
2021-08-06 11:57:54 +03:00
Roman Khimov
79bdf9b98f
Merge pull request #2115 from nspcc-dev/fix-ping-messages
...
network: fix Ping messages
2021-08-06 11:43:00 +03:00
Roman Khimov
f9663a97a1
network: fix Ping messages
...
* NewPing() accepts block index first and nonce then.
* Block height should be used, it'll be important for state exchanging nodes
2021-08-06 11:28:09 +03:00
Roman Khimov
39f874d03f
core: don't recalculate witness script hash
...
We know it already, but with current loading code VM will hash it once
more. It doesn't help a lot and still it costs nothing to avoid this
overhead.
name old time/op new time/op delta
VerifyWitness-8 93.4µs ± 3% 92.7µs ± 2% ~ (p=0.353 n=10+10)
name old alloc/op new alloc/op delta
VerifyWitness-8 3.43kB ± 0% 3.40kB ± 0% -0.70% (p=0.000 n=9+9)
name old allocs/op new allocs/op delta
VerifyWitness-8 67.0 ± 0% 66.0 ± 0% -1.49% (p=0.000 n=10+10)
2021-08-06 11:25:09 +03:00
Evgeniy Stratonikov
43ee671f36
mpt: do not allocate NodeObject for serialization
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-06 10:28:19 +03:00
Roman Khimov
e41fc2fd1b
Merge pull request #2111 from nspcc-dev/drop-refuel
...
native: drop Refuel method from GAS
2021-08-05 16:42:29 +03:00
Roman Khimov
f685c49cb2
Merge pull request #2110 from nspcc-dev/optimize-tx-decoding
...
Optimize tx decoding
2021-08-05 13:43:11 +03:00
Roman Khimov
d6bd6b6888
native: drop Refuel method from GAS
...
It can be used to attack the network (amplifying DOS), so it's broken
beyond repair. This reverts ac601601c1
.
See also neo-project/neo#2560 and neo-project/neo#2561 .
2021-08-05 10:27:13 +03:00
Roman Khimov
1b186e046b
network: use optimized decoder for transactions
...
NewTransactionFromBytes() works a bit faster and uses less memory.
2021-08-04 23:49:07 +03:00
Roman Khimov
892c9785ad
transaction: don't allocate new buffer to calculate hash
...
We can write directly to hash.Hash.
name old time/op new time/op delta
DecodeBinary-8 2.89µs ± 3% 2.82µs ± 5% ~ (p=0.052 n=10+10)
DecodeJSON-8 13.0µs ± 1% 12.8µs ± 1% -1.54% (p=0.002 n=10+8)
DecodeFromBytes-8 2.37µs ± 1% 2.25µs ± 5% -5.25% (p=0.000 n=9+10)
name old alloc/op new alloc/op delta
DecodeBinary-8 1.75kB ± 0% 1.53kB ± 0% -12.79% (p=0.000 n=10+10)
DecodeJSON-8 3.49kB ± 0% 3.26kB ± 0% -6.42% (p=0.000 n=10+10)
DecodeFromBytes-8 1.37kB ± 0% 1.14kB ± 0% -16.37% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
DecodeBinary-8 26.0 ± 0% 23.0 ± 0% -11.54% (p=0.000 n=10+10)
DecodeJSON-8 58.0 ± 0% 55.0 ± 0% -5.17% (p=0.000 n=10+10)
DecodeFromBytes-8 18.0 ± 0% 15.0 ± 0% -16.67% (p=0.000 n=10+10)
2021-08-04 23:43:20 +03:00
Roman Khimov
6d10cdc2f6
transaction: avoid ReadArray()
...
Reflection adds some real cost to it:
name old time/op new time/op delta
DecodeBinary-8 3.14µs ± 5% 2.89µs ± 3% -8.19% (p=0.000 n=10+10)
DecodeJSON-8 12.6µs ± 3% 13.0µs ± 1% +3.77% (p=0.000 n=10+10)
DecodeFromBytes-8 2.73µs ± 2% 2.37µs ± 1% -13.12% (p=0.000 n=9+9)
name old alloc/op new alloc/op delta
DecodeBinary-8 1.82kB ± 0% 1.75kB ± 0% -3.95% (p=0.000 n=10+10)
DecodeJSON-8 3.49kB ± 0% 3.49kB ± 0% ~ (all equal)
DecodeFromBytes-8 1.44kB ± 0% 1.37kB ± 0% -5.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
DecodeBinary-8 29.0 ± 0% 26.0 ± 0% -10.34% (p=0.000 n=10+10)
DecodeJSON-8 58.0 ± 0% 58.0 ± 0% ~ (all equal)
DecodeFromBytes-8 21.0 ± 0% 18.0 ± 0% -14.29% (p=0.000 n=10+10)
2021-08-04 23:34:57 +03:00
Roman Khimov
d2732a71d8
transaction: don't overwrite error and witnesses length check
...
ReadArray() can return some error and we shouldn't overwrite it. At the same
time limiting ReadArray() to the number of Signers can make it return wrong
error if the number of witnesses actually is bigger than the number of
signers, so use MaxAttributes.
2021-08-04 23:17:50 +03:00
Roman Khimov
d487b54612
transaction: don't recalculate size when decoding from buffer
...
name old time/op new time/op delta
DecodeBinary-8 3.17µs ± 6% 3.14µs ± 5% ~ (p=0.579 n=10+10)
DecodeJSON-8 12.8µs ± 3% 12.6µs ± 3% ~ (p=0.105 n=10+10)
DecodeFromBytes-8 3.45µs ± 4% 2.73µs ± 2% -20.70% (p=0.000 n=10+9)
name old alloc/op new alloc/op delta
DecodeBinary-8 1.82kB ± 0% 1.82kB ± 0% ~ (all equal)
DecodeJSON-8 3.49kB ± 0% 3.49kB ± 0% ~ (all equal)
DecodeFromBytes-8 1.82kB ± 0% 1.44kB ± 0% -21.05% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
DecodeBinary-8 29.0 ± 0% 29.0 ± 0% ~ (all equal)
DecodeJSON-8 58.0 ± 0% 58.0 ± 0% ~ (all equal)
DecodeFromBytes-8 29.0 ± 0% 21.0 ± 0% -27.59% (p=0.000 n=10+10)
2021-08-04 23:13:58 +03:00
Roman Khimov
5e18a6141e
Merge pull request #2106 from nspcc-dev/microopt
...
Microoptimizations
2021-08-03 21:28:35 +03:00
Roman Khimov
64c780ad7a
native: optimize totalSupply operations during token burn/mint
...
We burn GAS in OnPersist for every transaction so some buffer reuse here is
quite natural.
This also doesn't change a lot in the overall TPS picture, maybe adding some
1%.
2021-08-03 17:59:38 +03:00
Roman Khimov
dede4fa7b1
state: convert NEO balance to stack item directly
...
Avoid calling Append() that will reallocate the slice, we know the length of
the slice exactly.
2021-08-03 17:59:38 +03:00
Roman Khimov
5c65d33439
native: move required balance check to token contracts
...
Which duplicates the check, but deduplicates error path. This check forced
double balance deserialization which is quite costly operation, so we better
do it once.
It's hardly noticeable as of TPS metrics though, maybe some 1-2%%.
2021-08-03 17:59:38 +03:00
Roman Khimov
85936de254
vm: don't create reference counter when it's not needed
...
* invocation stack doesn't need refcounting
* exception stack doesn't need refcounting
* evaluation stack always has VM-level refcounter
2021-08-02 22:38:41 +03:00
Roman Khimov
2c2ccdca74
opcode: optimize IsValid
...
Map access costs much more than array access.
name old time/op new time/op delta
IsValid-8 17.6ns ± 2% 1.1ns ± 2% -93.68% (p=0.008 n=5+5)
2021-08-02 21:46:19 +03:00
Roman Khimov
3c1325035e
fee: use array for opcodes
...
Use less memory and have faster access.
name old time/op new time/op delta
Opcode1-8 22.4ns ± 6% 3.0ns ± 6% -86.63% (p=0.000 n=10+10)
2021-08-02 20:18:33 +03:00
Roman Khimov
dfc514eda0
Merge pull request #2102 from nspcc-dev/store4
...
Improve (*MemCachedStore).Persist
2021-08-02 20:10:05 +03:00
Roman Khimov
024bfee363
README: N3 is stable now
2021-08-02 20:08:39 +03:00
Roman Khimov
07febc10c7
CHANGELOG: release 0.97.0
2021-08-02 19:59:42 +03:00
Roman Khimov
82f481e143
Merge pull request #2105 from nspcc-dev/json-restrict
...
native/std: restrint amount of items in JSON deserialization
2021-08-02 19:41:54 +03:00
Evgeniy Stratonikov
bdb9748c1b
native/std: restrict amount of items in JSON deserialization
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-02 18:57:47 +03:00
Roman Khimov
f8174ca64c
core: ensure data logged is from persistent store
...
Using bc.dao here is wrong, it can contain unpersisted data.
2021-08-02 16:33:09 +03:00