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

Update tail padded shares with NMT wrapper #440

Merged
merged 3 commits into from
Jul 1, 2021
Merged

Conversation

Wondertan
Copy link
Member

@Wondertan Wondertan commented Jun 28, 2021

While wearing a debugging hat, confusing myself, and thinking about what went wrong and what could be done better, I found a better solution for #299. Also, removed one allocation in a hot path(wrapper.Push).

Addition: use one global tail padded share instead of generating them everytime

…tail padding and not in wrapper; -1 allocation
@Wondertan Wondertan requested review from liamsi and evan-forbes June 28, 2021 21:34
@Wondertan Wondertan self-assigned this Jun 28, 2021
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2021

Codecov Report

Merging #440 (efd2150) into master (8da1644) will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #440      +/-   ##
==========================================
- Coverage   61.76%   61.70%   -0.06%     
==========================================
  Files         263      263              
  Lines       23003    23010       +7     
==========================================
- Hits        14207    14198       -9     
- Misses       7292     7303      +11     
- Partials     1504     1509       +5     
Impacted Files Coverage Δ
p2p/ipld/wrapper/nmt_wrapper.go 83.33% <100.00%> (+9.25%) ⬆️
types/block.go 78.85% <100.00%> (ø)
types/share_splitting.go 97.50% <100.00%> (+0.06%) ⬆️
privval/signer_listener_endpoint.go 80.00% <0.00%> (-9.42%) ⬇️
privval/socket_listeners.go 78.72% <0.00%> (-4.26%) ⬇️
privval/secret_connection.go 72.68% <0.00%> (-3.61%) ⬇️
privval/signer_endpoint.go 75.75% <0.00%> (-3.04%) ⬇️
statesync/syncer.go 78.96% <0.00%> (-0.80%) ⬇️
blockchain/v0/pool.go 80.98% <0.00%> (-0.77%) ⬇️
consensus/state.go 67.57% <0.00%> (-0.28%) ⬇️
... and 7 more

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

another excellent refactor and bug fix!! 💯 🥇

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

I agree, this is dope! 👍🏼

shares[i] = NamespacedShare{
Share: append(
append(make([]byte, 0, shareWidth), consts.TailPaddingNamespaceID...),
bytes.Repeat([]byte{0}, shareWidth-consts.NamespaceSize)...,
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to move the bytes.Repeat([]byte{0}, shareWidth-consts.NamespaceSize) out of the for-loop? The compiler is probably smart enough to optimize this anyways but it would be slightly more readable with a proper var name imo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I think we can move out not just repeat but the whole slice in global var to be allocated once and reused everywhere. Shares are immutable so this should work and save us some RAM 😌

Furthermore, using a pointer for NamespaceShare instead of copying value should also give us a tiny win, though still a win. But this should be tackled together with whole Share struct revisiting, as it currently has an ID field which is totally unused, but still exist

@Wondertan Wondertan requested review from liamsi and evan-forbes June 29, 2021 11:57
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

only a optional nit, LGTM two thumbs up 👍 👍

🎆 🎇 ✨

Comment on lines 113 to 115
// tail is filler for all tail padded shares
// it is allocated once and used everywhere
var tail = append(
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe a slightly more descriptive name? it's not really necessary from a documentation standpoint, but it is a package var

Copy link
Member Author

Choose a reason for hiding this comment

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

Would you mind suggesting the name, as a native English speaker?

Copy link
Member

Choose a reason for hiding this comment

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

tailPaddingShare? just to match TailPaddingNamespace

Copy link
Member

Choose a reason for hiding this comment

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

tailPaddingShare is good IMO. I know Hlib prefers shorter var names but in this case the (global) variable should have a descriptive name. A shorter name would be OK, if the var was in the scope of the function itself.

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

This is dope. I agree with https://github.com/celestiaorg/lazyledger-core/pull/440/files#r661438921 but this is just a minor nit.

@Wondertan Wondertan merged commit 0fa5dce into master Jul 1, 2021
@Wondertan Wondertan deleted the hlib/tail-padding branch July 1, 2021 13:00
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.

4 participants