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

util: reduce allocations in util.Uint256DecodeStringLE #2133

Merged
merged 1 commit into from
Aug 17, 2021

Conversation

fyrchik
Copy link
Contributor

@fyrchik fyrchik commented Aug 17, 2021

It is used a lot in clients (including our benchmark).
Uint160 is already optimized.

name                     old time/op    new time/op    delta
Uint256DecodeStringLE-8     150ns ±15%     112ns ± 3%  -25.23%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
Uint256DecodeStringLE-8     96.0B ± 0%     64.0B ± 0%  -33.33%  (p=0.000 n=10+10)

name                     old allocs/op  new allocs/op  delta
Uint256DecodeStringLE-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)

Another reasonable step would be to use hex.Decode instead of DecodeString but then string is converted to []byte argument so there is still 1 allocation.

Signed-off-by: Evgeniy Stratonikov evgeniy@nspcc.ru

It is used a lot in clients (including our benchmark).
`Uint160` is already optimized.

```
name                     old time/op    new time/op    delta
Uint256DecodeStringLE-8     150ns ±15%     112ns ± 3%  -25.23%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
Uint256DecodeStringLE-8     96.0B ± 0%     64.0B ± 0%  -33.33%  (p=0.000 n=10+10)

name                     old allocs/op  new allocs/op  delta
Uint256DecodeStringLE-8      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
@codecov
Copy link

codecov bot commented Aug 17, 2021

Codecov Report

Merging #2133 (8c31831) into master (11351b9) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2133      +/-   ##
==========================================
+ Coverage   83.91%   83.98%   +0.07%     
==========================================
  Files         290      290              
  Lines       27336    27337       +1     
==========================================
+ Hits        22938    22960      +22     
+ Misses       3131     3108      -23     
- Partials     1267     1269       +2     
Impacted Files Coverage Δ
pkg/util/uint256.go 100.00% <100.00%> (ø)
pkg/network/server.go 73.95% <0.00%> (+0.12%) ⬆️
pkg/services/oracle/request.go 62.50% <0.00%> (+3.26%) ⬆️
pkg/core/native/ledger.go 93.96% <0.00%> (+3.44%) ⬆️
pkg/services/oracle/oracle.go 86.48% <0.00%> (+9.00%) ⬆️

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 11351b9...8c31831. Read the comment docs.

@roman-khimov roman-khimov added this to the v0.97.2 milestone Aug 17, 2021
@roman-khimov roman-khimov merged commit 483934d into master Aug 17, 2021
@roman-khimov roman-khimov deleted the optimize-util branch August 17, 2021 16:20
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