10000 [Consensus] Cheap message comparison by hyunsooda · Pull Request #1712 · klaytn/klaytn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

[Consensus] Cheap message comparison #1712

Merged
merged 8 commits into from
Jul 4, 2023
Merged

Conversation

hyunsooda
Copy link
Contributor
@hyunsooda hyunsooda commented Nov 21, 2022

Proposed changes

Consensus messages are basically compared two times in one round if no round change happens. The number of comparisons depends on how many committees participate at each round. For 4 CNs, total of 8 times compared. This PR proposes a cheap comparison. This change was inspired by @hqjang-pepper 's presentation.

BenchmarkMsgCmp/reflect.DeepEqual-20              819708              1399 ns/op
BenchmarkMsgCmp/own-20                          72292522                16.41 ns/op

cc. @jiseongnoh , @yoomee1313, @mckim19

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@blukat29
Copy link
Contributor

Please add a test case. If we ever add a field, we might forget to update the Equal method.

})

// Better
b.Run("cmp", func(b *testing.B) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have no idea where "gotest.tools/assert/cmp" is from. is the import related to this improvement?

Copy link
Contributor Author
@hyunsooda hyunsooda Nov 21, 2022

Choose a reason for hiding this comment

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

Yes, but I forgot to remove its comparison since it cannot be used in production env. Now it's removed.

})

// Best
b.Run("own", func(b *testing.B) {
Copy link
Contributor
@jiseongnoh jiseongnoh Nov 21, 2022

Choose a reason for hiding this comment

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

Could you make some test codes that verify this improvement does not make any problems with consensus? Thank you in advance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I did not get the meaning of "own" here. Does it mean it is your own code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. TC added.
  2. own indicates a newly added comparison method. Any suggestion for renaming?

Copy link
Contributor
@jiseongnoh jiseongnoh Nov 21, 2022

Choose a reason for hiding this comment

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

how about "precompiledEqual"? or "staticDeepEqual"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.., I think just a EuqalImpl seems enough. The suggested names seem overly named than it does actually.

@hyunsooda
Copy link
Contributor Author

@blukat29, Thanks. added.

@kjhman21
Copy link

@hyunsooda This is too late to be added. I think this can be merged after v1.10 is released. Is it okay to you?
cc @jiseongnoh @blukat29

@yoomee1313 yoomee1313 requested review from kjhman21 and removed request for yoomee1313 December 27, 2022 08:46
@blukat29
Copy link
Contributor
blukat29 commented Jan 3, 2023

@hyunsooda Can you rebase against the latest dev? Then I think linter can pass.

the confirmation of the same output with the previous one
blukat29
blukat29 previously approved these changes Jan 16, 2023
@blukat29
Copy link
Contributor

@hyunsooda Could you rebase against the latest dev please?

@hyunsooda
Copy link
Contributor Author

Apologies for the delay. I will proceed with the next steps if this change is deemed feasible and desirable for merging. If not, please inform me, and I will close it.

jiseongnoh
jiseongnoh previously approved these changes Mar 14, 2023
Copy link
Contributor
@jiseongnoh jiseongnoh left a comment

Choose a reason for hiding this comment

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

Thank you for the optimization.

@hyunsooda hyunsooda dismissed stale reviews from jiseongnoh an 6DB6 d blukat29 via adeb45e June 21, 2023 01:33
@yoomee1313
Copy link
Contributor

@hyunsooda Could you resolve the test-linter?

@blukat29 blukat29 merged commit 7154c99 into klaytn:dev Jul 4, 2023
@aidan-kwon aidan-kwon mentioned this pull request Aug 3, 2023
20 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0