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

crypto/types: optimize compact bit array one count #9216

Merged
merged 3 commits into from
Apr 30, 2021
Merged

crypto/types: optimize compact bit array one count #9216

merged 3 commits into from
Apr 30, 2021

Conversation

cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Apr 28, 2021

Description

By using bits.OnesCount8 instead of bitwise operations.

Benchmark result on Apple M1:

name                     old time/op    new time/op    delta
NumTrueBitsBefore/new-8    88.5ns ± 1%     9.1ns ± 0%  -89.68%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
NumTrueBitsBefore/new-8     0.00B          0.00B          ~     (all equal)

name                     old allocs/op  new allocs/op  delta
NumTrueBitsBefore/new-8      0.00           0.00          ~     (all equal)

Fixes #9125


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 28, 2021

cc @odeke-em

@codecov
Copy link

codecov bot commented Apr 28, 2021

Codecov Report

Merging #9216 (0a611f4) into master (f04b5dc) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9216      +/-   ##
==========================================
- Coverage   60.12%   60.12%   -0.01%     
==========================================
  Files         595      595              
  Lines       37190    37188       -2     
==========================================
- Hits        22361    22359       -2     
  Misses      12848    12848              
  Partials     1981     1981              
Impacted Files Coverage Δ
crypto/types/compact_bit_array.go 77.39% <100.00%> (-0.39%) ⬇️

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

let's clean the inner loop

crypto/types/compact_bit_array.go Show resolved Hide resolved
@cuonglm cuonglm requested a review from robert-zaremba April 28, 2021 15:09
@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 28, 2021

CI fails because of #9010, TestPaginatedVotesQuery

@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 28, 2021

CI fails because of #9010, TestPaginatedVotesQuery

#9223 will fix this.

@cyberbono3 cyberbono3 self-requested a review April 29, 2021 03:14
By using bits.OnesCount8 instead of bitwise operations.

Benchmark result on Apple M1:

name                     old time/op    new time/op    delta
NumTrueBitsBefore/new-8    88.5ns ± 1%     9.1ns ± 0%  -89.68%  (p=0.000 n=10+10)

name                     old alloc/op   new alloc/op   delta
NumTrueBitsBefore/new-8     0.00B          0.00B          ~     (all equal)

name                     old allocs/op  new allocs/op  delta
NumTrueBitsBefore/new-8      0.00           0.00          ~     (all equal)

Fixes #9125
@cuonglm
Copy link
Contributor Author

cuonglm commented Apr 30, 2021

Kindly ping @robert-zaremba @odeke-em

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

Thanks, good improvement, and code reduction !

@aaronc aaronc added the A:automerge Automatically merge PR once all prerequisites pass. label Apr 30, 2021
@mergify mergify bot merged commit 72873a0 into cosmos:master Apr 30, 2021
@cuonglm
Copy link
Contributor Author

cuonglm commented May 4, 2021

Ops, wrong issue reference, should be #9215

@odeke-em odeke-em deleted the cuonglm/optimize-compact-bit-array-bits-count branch May 4, 2021 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants