Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup stackitem json serialization #2053

Merged
merged 6 commits into from
Jul 13, 2021
Merged

Speedup stackitem json serialization #2053

merged 6 commits into from
Jul 13, 2021

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Jul 9, 2021

Cache already marshaled values.
The expected memory overhead is linear (map itself + living references to the old buffer memory in case it grows with reallocation).

@roman-khimov
Copy link
Member

living references to the old buffer memory in case it grows with reallocation

map[Item]struct{start int, end int}?

Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried about our test coverage after these changes. Do we hit every corner case with our current test set? But it looks good otherwise.

pkg/vm/stackitem/serialization.go Outdated Show resolved Hide resolved
pkg/io/binaryWriter.go Outdated Show resolved Hide resolved
pkg/vm/stackitem/serialization.go Outdated Show resolved Hide resolved
pkg/vm/stackitem/serialization.go Outdated Show resolved Hide resolved
pkg/vm/stackitem/serialization.go Outdated Show resolved Hide resolved
pkg/vm/stackitem/serialization.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 12, 2021

Codecov Report

Merging #2053 (0611031) into master (1853d0c) will increase coverage by 1.19%.
The diff coverage is 94.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2053      +/-   ##
==========================================
+ Coverage   83.15%   84.34%   +1.19%     
==========================================
  Files         287      287              
  Lines       23419    26939    +3520     
==========================================
+ Hits        19473    22722    +3249     
- Misses       2736     2991     +255     
- Partials     1210     1226      +16     
Impacted Files Coverage Δ
pkg/vm/stackitem/json.go 96.87% <92.15%> (-0.03%) ⬇️
pkg/vm/stackitem/serialization.go 95.39% <95.58%> (+0.95%) ⬆️
pkg/io/binaryWriter.go 100.00% <100.00%> (ø)
pkg/vm/exception.go 38.46% <0.00%> (-11.54%) ⬇️
pkg/vm/context.go 87.09% <0.00%> (-3.82%) ⬇️
cli/main.go 75.00% <0.00%> (-3.58%) ⬇️
pkg/consensus/prepare_request.go 80.00% <0.00%> (-3.34%) ⬇️
pkg/rpc/response/errors.go 84.00% <0.00%> (-2.67%) ⬇️
cli/util/convert.go 70.00% <0.00%> (-2.23%) ⬇️
cli/vm/vm.go 60.00% <0.00%> (-1.54%) ⬇️
... and 280 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1853d0c...0611031. Read the comment docs.

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
```
name      old time/op    new time/op    delta
ToJSON-8    4.52ms ± 4%    0.05ms ±34%  -98.89%  (p=0.000 n=8+10)

name      old alloc/op   new alloc/op   delta
ToJSON-8    2.13MB ± 0%    0.40MB ± 0%  -81.44%  (p=0.000 n=9+6)

name      old allocs/op  new allocs/op  delta
ToJSON-8     65.6k ± 0%      0.0k ± 0%  -99.95%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
```
name      old time/op    new time/op    delta
ToJSON-8    50.3µs ±34%    47.8µs ± 9%     ~     (p=0.971 n=10+10)

name      old alloc/op   new alloc/op   delta
ToJSON-8     396kB ± 0%     396kB ± 0%   -0.10%  (p=0.000 n=6+10)

name      old allocs/op  new allocs/op  delta
ToJSON-8      34.0 ± 0%      18.0 ± 0%  -47.06%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
```
name            old time/op    new time/op    delta
EncodeBinary-8    10.6ms ± 1%     8.4ms ± 1%  -20.94%  (p=0.000 n=9+10)

name            old alloc/op   new alloc/op   delta
EncodeBinary-8    1.64MB ± 0%    2.24MB ± 0%  +36.18%  (p=0.000 n=8+9)

name            old allocs/op  new allocs/op  delta
EncodeBinary-8      131k ± 0%       66k ± 0%  -49.98%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
```
name            old time/op    new time/op    delta
EncodeBinary-8    8.39ms ± 1%    0.05ms ±21%  -99.44%  (p=0.000 n=10+9)

name            old alloc/op   new alloc/op   delta
EncodeBinary-8    2.24MB ± 0%    0.33MB ± 0%  -85.29%  (p=0.000 n=9+10)

name            old allocs/op  new allocs/op  delta
EncodeBinary-8     65.6k ± 0%      0.0k ± 0%  -99.95%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
@roman-khimov roman-khimov merged commit d638aee into master Jul 13, 2021
@roman-khimov roman-khimov deleted the stackitem-json branch July 13, 2021 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants