Roman Khimov
1b83dc2476
*: improve for loop syntax
...
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also
prefers ranging over slices where possible (it makes code a little better to
read).
Notice that we have a number of dangerous loops where slices are mutated
during loop execution, many of these can't be converted since we need proper
length evalutation at every iteration.
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:45:18 +03:00
Roman Khimov
a30792dbb6
*: use slices.Index/slices.Contains where appropriate
...
This doesn't touch performance-sensitive parts, but simplifies a lot of code.
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
93ecd61079
stackitem: microoptimize memory management of Make()
...
Preallocate as much as needed.
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-27 08:24:52 +03:00
Roman Khimov
9e112fc024
*: use slices.Clone instead of make/copy
...
It's much easier this way.
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
d9ee31fb52
*: use clear() to clear maps
...
Supposedly more efficient since we can avoid some memory management dances.
Memory pool agrees:
goos: linux
goarch: amd64
pkg: github.com/nspcc-dev/neo-go/pkg/core/mempool
cpu: AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics
│ pool.old │ pool.new │
│ sec/op │ sec/op vs base │
Pool/one,_incr_fee-16 12.44m ± 1% 12.51m ± 1% +0.55% (p=0.029 n=10)
Pool/many,_same_fee-16 4.960m ± 2% 3.100m ± 1% -37.50% (p=0.000 n=10)
Pool/many,_incr_fee-16 16.03m ± 2% 14.11m ± 1% -12.00% (p=0.000 n=10)
Pool/one,_same_fee-16 1.742m ± 1%
geomean 9.964m 5.556m -17.92%
│ pool.old │ pool.new │
│ B/op │ B/op vs base │
Pool/one,_incr_fee-16 8.117Ki ± 120% 7.101Ki ± 128% -12.52% (p=0.022 n=10)
Pool/many,_same_fee-16 3941.2Ki ± 0% 805.4Ki ± 0% -79.56% (p=0.000 n=10)
Pool/many,_incr_fee-16 3936.2Ki ± 0% 829.8Ki ± 0% -78.92% (p=0.000 n=10)
Pool/one,_same_fee-16 12.98Ki ± 10%
geomean 501.2Ki 88.59Ki -66.47%
│ pool.old │ pool.new │
│ allocs/op │ allocs/op vs base │
Pool/one,_incr_fee-16 28.00 ± 21% 24.00 ± 21% -14.29% (p=0.002 n=10)
Pool/many,_same_fee-16 40.38k ± 0% 40.03k ± 0% -0.86% (p=0.000 n=10)
Pool/many,_incr_fee-16 40.38k ± 0% 40.04k ± 0% -0.85% (p=0.000 n=10)
Pool/one,_same_fee-16 23.00 ± 4%
geomean 3.574k 969.8 -5.55%
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-24 22:41:48 +03:00
Roman Khimov
1c1d77c9b8
*: make use of min/max where appropriate
...
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-23 22:11:29 +03:00
Anna Shaleva
55fa12355e
stackitem: extend Make() with []string
...
Allow []string to be converted to stackitem.Item.
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-06-11 17:50:53 +03:00
Anna Shaleva
8162e9033d
*: replace slice.Copy with bytes.Clone
...
And refactor some code a bit, don't use bytes.Clone where type-specific
helpers may be used instead.
Close #2907 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-03-05 13:54:10 +03:00
Anna Shaleva
0c6627f13d
*: use multierror wrapping where possible
...
Revert 5f6c01336c
, remove all multierror
related nolint comments and use multierror wrapping instead.
Close #2906 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2024-03-05 13:54:10 +03:00
Anna Shaleva
387c411da0
vm: add default limit to SI serialization context
...
Follow the notion of https://github.com/neo-project/neo/pull/2948 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-11-22 19:39:01 +03:00
Anna Shaleva
b0cdae4666
vm: reduce maximum stckitem size
...
To prevent possible DoS. Port the https://github.com/neo-project/neo-vm/pull/514 ,
close #3170 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-11-13 20:40:30 +03:00
Anna Shaleva
39ce3a9d1d
vm: fix linter warning
...
Fix the following linter warning:
```
indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-10-20 17:22:21 +03:00
Anna Shaleva
624f193f94
vm: move JNumbers parsing precision under HFBasilisk
...
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-10 13:14:16 +03:00
Anna Shaleva
d90608ddbf
vm: increase BigInt parsing precision
...
Follow the https://github.com/neo-project/neo/pull/2883 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-10 13:14:16 +03:00
Anna Shaleva
4be692193e
vm: allow parsing scientific JSON numbers
...
52-bit precision is not enough for our 256-bit VM, but this value
matches the reference implementation, see the
https://github.com/neo-project/neo/issues/2879 .
MaxIntegerPrec will be increased (or even removed) as soon as the
ref. issue is resolved.
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-07-31 17:19:05 +03:00
Anna Shaleva
71bcb8bade
native: allow to use EQUAL opcode for BLS12-381 points comparison
...
That's the way how C# node handles equality checks for stackitem.Interop types
for these points. Ref. https://github.com/nspcc-dev/neo-go/issues/3002#issuecomment-1591220501 .
Along the way, add GT case for CryptoLib's bls12381Equal method. It should be there since #2940 .
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-06-15 15:00:27 +03:00
Anna Shaleva
8e085d3ca3
vm: allow to make stackitem from *Uint160 and *Uint256
...
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-17 11:16:32 +03:00
Roman Khimov
433275265f
*: use require.ErrorIs instead of require.True(t, error.Is())
...
This is just a much better way to do the same thing. Inspired by
nspcc-dev/neofs-sdk-go#407 .
Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-05-04 17:03:47 +03:00
Anna Shaleva
6b21ad9922
*: replace interface{}
with any
keyword
...
Everywhere including examples, external interop APIs, bindings generators
code and in other valuable places. A couple of `interface{}` usages are
intentionally left in the CHANGELOG.md, documentation and tests.
2023-04-04 13:22:42 +03:00
Anna Shaleva
5f6c01336c
*: add nolint comments to multiple errors wrapping
...
To be enabled after go 1.20 support is added.
2023-03-15 16:38:01 +03:00
Anna Shaleva
25ed5fcd60
vm: allow custom limit duing Map\Array\Struct deserialization
2023-02-08 10:58:55 +03:00
Anna Shaleva
15fa65d30f
vm: export stackitem's deserContext
2023-02-08 10:58:54 +03:00
Roman Khimov
9ba18b5dfa
stackitem: serialize/deserialize pointers, fix #2815
...
They of course can't be serialized, but in protected mode we still need to
handle them somehow.
2022-11-20 16:02:50 +03:00
Anna Shaleva
7eb87afab8
cli: unify parameters parsing
...
Share parameters parsing code between 'contract invokefunction' and
'vm run' commands. It allows VM CLI to parse more complicated parameter
types including arrays and file-backed bytestrings.
2022-10-13 08:20:27 +03:00
Roman Khimov
4f3ffe7290
golangci: enable errorlint and fix everything it found
2022-09-02 18:36:23 +03:00
Anna Shaleva
916f2293b8
*: apply go 1.19 formatter heuristics
...
And make manual corrections where needed. See the "Common mistakes
and pitfalls" section of https://tip.golang.org/doc/comment .
2022-08-09 15:37:52 +03:00
Roman Khimov
edb6ca8926
Merge pull request #2531 from nspcc-dev/perf
...
Minor performance improvements
2022-06-03 10:40:56 +03:00
Roman Khimov
c3d989ebda
stackitem: reusable serialization context
...
We serialize items a lot and this allows to avoid a number of allocations.
2022-06-02 15:38:39 +03:00
Roman Khimov
e1607e23c2
Merge pull request #2525 from nspcc-dev/immutable-items
...
vm: implement immutable stackitems
2022-05-31 10:36:56 +03:00
Anna Shaleva
42a051e55a
core: DeepCopy notifiction event args inside System.Runtime.Notify
2022-05-31 08:07:53 +03:00
Anna Shaleva
7296f0c913
vm: support immutable compound types
2022-05-31 08:07:50 +03:00
Anna Shaleva
a3285eae04
vm: stringify InteropInterface stackitem type as InteropInterface
2022-05-25 13:20:21 +03:00
Roman Khimov
c6f8c33e66
Merge pull request #2478 from nspcc-dev/mainnet-fixes
...
Mainnet fixes
2022-05-12 10:04:53 +03:00
Roman Khimov
621db8c832
stackitem: allow to unJSONize big numbers (>int64), fix #2477
...
100000000000000000000 overflows int64 and NeoGo returns some garbage to
contracts instead of a proper number.
2022-05-11 21:03:10 +03:00
Anna Shaleva
8af043520d
vm: adjust MaxByteArrayComparableSize value
...
https://github.com/neo-project/neo-vm/pull/454#discussion_r857533800 .
2022-05-07 12:56:09 +03:00
Anna Shaleva
23b78b0be2
vm: limit ByteArray comparable length
...
Close #2460 .
2022-05-07 12:56:04 +03:00
Elizaveta Chichindaeva
28908aa3cf
[ #2442 ] English Check
...
Signed-off-by: Elizaveta Chichindaeva <elizaveta@nspcc.ru>
2022-05-04 19:48:27 +03:00
Evgeniy Stratonikov
a8d2df874f
stackitem: limit JSON size in ToJSONWithTypes
...
Also do not limit depth. It was introduced in e34fa2e915
as a simple
solution to OOM problem. In this commit we do exactly the refactoring
described there. Maximum size is the same as stack item size and
can be changed if needed withouth significat refactoring.
`1 MiB` seems sufficient, though.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-03-09 10:29:23 +03:00
Evgeniy Stratonikov
c72b3f2176
vm/emit: check big integer size
...
Fix a bug where big integer could be emitted as 0 without reporting an
error. Also, add tests.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2022-02-11 12:48:55 +03:00
Roman Khimov
decff2bfb9
stackitem: simplify extracting value from map
...
Going through interfaces doesn't make it faster.
2021-12-01 21:36:35 +03:00
Roman Khimov
af8a4da6d9
stackitem: use type switch more effectively
...
Reduce the number of allocations, save some time.
name old time/op new time/op delta
EncodeBinary-8 51.2µs ± 8% 44.6µs ± 7% -12.79% (p=0.008 n=5+5)
SerializeSimple-8 523ns ± 5% 449ns ± 4% -14.27% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
EncodeBinary-8 329kB ± 0% 329kB ± 0% -0.12% (p=0.008 n=5+5)
SerializeSimple-8 432B ± 0% 408B ± 0% -5.56% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
EncodeBinary-8 36.0 ± 0% 20.0 ± 0% -44.44% (p=0.008 n=5+5)
SerializeSimple-8 7.00 ± 0% 6.00 ± 0% -14.29% (p=0.008 n=5+5)
2021-12-01 21:36:35 +03:00
Roman Khimov
3eed9d06f8
stackitem: add some hint to 'seen' maps
...
It's empirical, we usually have one container, but four is likely to fit most
of regular cases.
2021-12-01 21:36:25 +03:00
Roman Khimov
d3198c3082
stackitem: avoid going through Value() in serialization
...
Doesn't change much, but still simpler.
name old time/op new time/op delta
SerializeSimple-8 452ns ±10% 435ns ± 4% ~ (p=0.356 n=10+9)
name old alloc/op new alloc/op delta
SerializeSimple-8 432B ± 0% 432B ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
SerializeSimple-8 7.00 ± 0% 7.00 ± 0% ~ (all equal)
2021-08-23 18:29:07 +03:00
Evgeniy Stratonikov
6879f76a13
stackitem: make Buffer
an alias to []byte
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-13 14:41:26 +03:00
Evgeniy Stratonikov
1dfef4ba26
stackitem: make ByteArray
an alias to []byte
...
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-13 14:41:26 +03:00
Evgeniy Stratonikov
4f98ec2f53
vm: embed reference counter in compound items
...
```
name old time/op new time/op delta
RefCounter_Add-8 44.8ns ± 4% 11.7ns ± 3% -73.94% (p=0.000 n=10+10)
```
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-13 14:41:26 +03:00
Evgeniy Stratonikov
a5516e8c96
stackitem: make BigInteger
alias to big.Int
...
Remove one indirection step.
``
name old time/op new time/op delta
MakeInt-8 79.7ns ± 8% 56.2ns ± 8% -29.44% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
MakeInt-8 48.0B ± 0% 40.0B ± 0% -16.67% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
MakeInt-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-12 17:53:36 +03:00
Evgeniy Stratonikov
cff8b1c24e
stackitem: use Bool
item directly
...
It is always copied.
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
2021-08-12 17:53:36 +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
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