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

common/hexutil: Improve Performance of EncodeBig(...) #23780

Merged
merged 1 commit into from
Oct 21, 2021
Merged

common/hexutil: Improve Performance of EncodeBig(...) #23780

merged 1 commit into from
Oct 21, 2021

Conversation

lmittmann
Copy link
Contributor

@lmittmann lmittmann commented Oct 20, 2021

  • fmt.Sprintf(...) to big.Int.Text(16)
  • reduced allocs from 6 to 2
  • improved speed
  • removed comment // The sign of the integer is ignored. as the tests state otherwise.

Benchmark:

goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/common/hexutil
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz

name                                          old time/op    new time/op    delta
EncodeBig/0x0-8                                 2.35ns ± 6%    2.01ns ± 1%  -14.76%  (p=0.000 n=10+9)
EncodeBig/0x1-8                                  401ns ± 9%      66ns ± 5%  -83.54%  (p=0.000 n=9+10)
EncodeBig/0xff-8                                 404ns ±10%      81ns ± 8%  -79.85%  (p=0.000 n=10+10)
EncodeBig/0x112233445566778899aabbccddeeff-8     548ns ± 8%     206ns ±14%  -62.48%  (p=0.000 n=10+10)
EncodeBig/0x80a7f2c1bcc396c00-8                  513ns ± 8%     163ns ± 9%  -68.16%  (p=0.000 n=10+10)
EncodeBig/-0x80a7f2c1bcc396c00-8                 565ns ±11%     158ns ±12%  -72.07%  (p=0.000 n=10+10)

name                                          old alloc/op   new alloc/op   delta
EncodeBig/0x0-8                                  0.00B          0.00B          ~     (all equal)
EncodeBig/0x1-8                                  40.0B ± 0%      4.0B ± 0%  -90.00%  (p=0.000 n=10+10)
EncodeBig/0xff-8                                 40.0B ± 0%      8.0B ± 0%  -80.00%  (p=0.000 n=10+10)
EncodeBig/0x112233445566778899aabbccddeeff-8     96.0B ± 0%     64.0B ± 0%  -33.33%  (p=0.000 n=10+10)
EncodeBig/0x80a7f2c1bcc396c00-8                  80.0B ± 0%     48.0B ± 0%  -40.00%  (p=0.000 n=10+10)
EncodeBig/-0x80a7f2c1bcc396c00-8                 88.0B ± 0%     48.0B ± 0%  -45.45%  (p=0.000 n=10+10)

name                                          old allocs/op  new allocs/op  delta
EncodeBig/0x0-8                                   0.00           0.00          ~     (all equal)
EncodeBig/0x1-8                                   6.00 ± 0%      2.00 ± 0%  -66.67%  (p=0.000 n=10+10)
EncodeBig/0xff-8                                  6.00 ± 0%      2.00 ± 0%  -66.67%  (p=0.000 n=10+10)
EncodeBig/0x112233445566778899aabbccddeeff-8      6.00 ± 0%      2.00 ± 0%  -66.67%  (p=0.000 n=10+10)
EncodeBig/0x80a7f2c1bcc396c00-8                   6.00 ± 0%      2.00 ± 0%  -66.67%  (p=0.000 n=10+10)
EncodeBig/-0x80a7f2c1bcc396c00-8                  7.00 ± 0%      2.00 ± 0%  -71.43%  (p=0.000 n=10+10)

- `fmt.Sprintf(...)` to `big.Int.Text(16)`
- reduced allocs from 6 to 2
- improved speed
@fjl fjl merged commit 2954f40 into ethereum:master Oct 21, 2021
@fjl fjl modified the milestones: Backlog, 1.10.12 Oct 21, 2021
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Oct 21, 2021
- use Text instead of fmt.Sprintf
- reduced allocs from 6 to 2
- improved speed
yongjun925 pushed a commit to DODOEX/go-ethereum that referenced this pull request Dec 3, 2022
- use Text instead of fmt.Sprintf
- reduced allocs from 6 to 2
- improved speed
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.

2 participants