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

refactor: deduplicate integer serialization in RollingBloom benchmark #24088

Closed
wants to merge 1 commit into from

Conversation

phyBrackets
Copy link
Contributor

@phyBrackets phyBrackets commented Jan 17, 2022

refactor: deduplicate integer serialization in RollingBloom benchmark and i think we have to follow don't repeat yourself pattern here! I don't think that this much affect the memory and efficiency because it is still in constant time . But surely it reduces some readability of code which is not the big headache for sure.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Seems like you could also simply use the helpers WriteLE32 and WriteBE32 from the <crypto/common.h> header in this case to avoid manual bit-fiddling:

void static inline WriteLE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htole32(x);
memcpy(ptr, (char*)&v, 4);
}

void static inline WriteBE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htobe32(x);
memcpy(ptr, (char*)&v, 4);
}

As PR and commit subject I'd suggest using something more concrete like "refactor: deduplicate integer serialization in RollingBloom benchmark", rather than a (rhetorical) question.

@phyBrackets phyBrackets changed the title shouldn't we follow DRY principle here? refactor: deduplicate integer serialization in RollingBloom benchmark Jan 17, 2022
@phyBrackets phyBrackets reopened this Jan 17, 2022
@phyBrackets
Copy link
Contributor Author

Thanks for the suggestion. I update the following.
@theStack

data[1] = (count >> 8) & 0xFF;
data[2] = (count >> 16) & 0xFF;
data[3] = (count >> 24) & 0xFF;
for(int i = 0; i <= 3; i++){
Copy link
Member

Choose a reason for hiding this comment

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

This is just WriteLE32(data, count);.

data[1] = (count >> 16) & 0xFF;
data[2] = (count >> 8) & 0xFF;
data[3] = count & 0xFF;
for(int i = 3; i >= 0; i--){
Copy link
Member

Choose a reason for hiding this comment

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

This is just WriteBE32(data, count);.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, should i change the following to just a function call by adding common.h header ?

Copy link
Member

@sipa sipa Feb 4, 2022

Choose a reason for hiding this comment

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

Yeah, better than duplicating the logic here.

@fanquake
Copy link
Member

Once you've addressed the suggestions, make sure you squash your changes to a single commit, with a proper commit message.

@phyBrackets
Copy link
Contributor Author

Once you've addressed the suggestions, make sure you squash your changes to a single commit, with a proper commit message.

@fanquake will take care of that. Thanks.

@phyBrackets
Copy link
Contributor Author

Seems like you could also simply use the helpers WriteLE32 and WriteBE32 from the <crypto/common.h> header in this case to avoid manual bit-fiddling:

void static inline WriteLE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htole32(x);
memcpy(ptr, (char*)&v, 4);
}

void static inline WriteBE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htobe32(x);
memcpy(ptr, (char*)&v, 4);
}

As PR and commit subject I'd suggest using something more concrete like "refactor: deduplicate integer serialization in RollingBloom benchmark", rather than a (rhetorical) question.

Isn't this bit inefficient because we are actually dropping the whole content of common.h ?

@phyBrackets
Copy link
Contributor Author

Seems like you could also simply use the helpers WriteLE32 and WriteBE32 from the <crypto/common.h> header in this case to avoid manual bit-fiddling:

void static inline WriteLE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htole32(x);
memcpy(ptr, (char*)&v, 4);
}

void static inline WriteBE32(unsigned char* ptr, uint32_t x)
{
uint32_t v = htobe32(x);
memcpy(ptr, (char*)&v, 4);
}

As PR and commit subject I'd suggest using something more concrete like "refactor: deduplicate integer serialization in RollingBloom benchmark", rather than a (rhetorical) question.

Isn't this bit inefficient because we are actually dropping the whole content of common.h ?

Hey @sipa what's your views on this before making a function call ?

@sipa
Copy link
Member

sipa commented Feb 4, 2022

I don't understand your question. Using ReadLE32/WriteLE32 is almost certainly more efficient than reimplementing it yourself (they're written in a way that the compiler can easily optimize out). Not that ~nanosecond level performance is relevant here...

@phyBrackets
Copy link
Contributor Author

oh , okay ! Then it's fine I think.

@phyBrackets
Copy link
Contributor Author

Sorry for the direct commit , need to do some more changes.

@phyBrackets
Copy link
Contributor Author

Hey, any update on this?

@maflcko
Copy link
Member

maflcko commented Feb 12, 2022

I haven't looked at the changes, but this can't be merged unless squashed.

Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits

@phyBrackets
Copy link
Contributor Author

Cool, will do that soon. Thanks!

@phyBrackets
Copy link
Contributor Author

Hey, I'm having some problem with squashing the commits. Should I make new PR with final changes? Will close this and refer to this PR! If you would allow?

@fanquake
Copy link
Member

Should I make new PR with final changes?

No. Please don't open new PRs for the same changes. You might need to take another look through: https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits/.

@phyBrackets
Copy link
Contributor Author

Hey @fanquake , I tried to rebase/squash , I have some problems with branches I think , there is branch conflict . I really don't want to open a new PR but it seems the only option , by the way if you would allow, I'll open that and set the reference to this PR , and will close this pr ?

@sipa
Copy link
Member

sipa commented Feb 17, 2022

@phyBrackets It's probably worthwhile learning how to resolve these issues anyway, if you want to continue contributing, whether you do that for this PR or a future one.

src/bench/rollingbloom.cpp Outdated Show resolved Hide resolved
@phyBrackets
Copy link
Contributor Author

@phyBrackets It's probably worthwhile learning how to resolve these issues anyway, if you want to continue contributing, whether you do that for this PR or a future one.

Hey @sipa , I'm really trying and searching around how to resolve this issue but I'm not able to , actually when I' trying to run git rebase -i HEAD~7 , this only shows the first 4 commits.

@maflcko
Copy link
Member

maflcko commented Feb 19, 2022

Your branch contains merge commits, which can't be squashed in a rebase.

Something like this might work (untested!!):

git checkout patch-1                                       # Verify this is on commit aa91fd400a6a23feeacdff0d2adacd18dd313e47
git fetch origin 5d254a234d8c1569b0161264cc6d5d8d0ce0d864  # Fetch the latest master
git merge 5d254a234d8c1569b0161264cc6d5d8d0ce0d864         # Merge the latest master
git reset --soft 5d254a234d8c1569b0161264cc6d5d8d0ce0d864  # Discard commit history, but keep all changes staged
git commit --message="bla bla"                             # Create a commit with all staged changes
git push origin patch-1 --force

@phyBrackets
Copy link
Contributor Author

I tried this , it seems more mess tho.

@maflcko
Copy link
Member

maflcko commented Feb 19, 2022

After the steps in #24088 (comment) you need to force push, not merge

@phyBrackets
Copy link
Contributor Author

Thank you sm @MarcoFalke . It seems like it works fine.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK e1fcf8d

Nit: I don't think the dataPtr pointer is really needed here, you could just call the serialization helper functions with data.data() as first parameter each.

@phyBrackets
Copy link
Contributor Author

Cool, but I think it is more readable through this . But yeah if this affects on unnecessary memory use. We can remove that. Let me know your further take on this.

@laanwj
Copy link
Member

laanwj commented Apr 6, 2022

Nit: I don't think the dataPtr pointer is really needed here, you could just call the serialization helper functions with data.data() as first parameter each.

+1. The assignment is unnecessary. I doubt it affects memory use in any significant way but I see no reason not to write it shorter if you're touching this code anyway.

@fanquake
Copy link
Member

fanquake commented Apr 6, 2022

I've just gone ahead and fixed this up in #24784, given this is straightforward, and likely been open long enough.

@fanquake fanquake closed this Apr 6, 2022
maflcko pushed a commit that referenced this pull request Apr 7, 2022
…loom benchmark

fff9141 refactor: Remove deduplication of data in rollingbloom bench (phyBrackets)

Pull request description:

  Fixed up #24088.

ACKs for top commit:
  vincenzopalazzo:
    ACK fff9141

Tree-SHA512: 9fef617bceb74a1aec4f4a1e7c4732c4764af3e8ac2fc02b84ce370e8b97431957ca17ee8f44fb96765f7304f8d7e5bfb951440db98ba40f240612f2232d215e
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 7, 2022
…ollingBloom benchmark

fff9141 refactor: Remove deduplication of data in rollingbloom bench (phyBrackets)

Pull request description:

  Fixed up bitcoin#24088.

ACKs for top commit:
  vincenzopalazzo:
    ACK bitcoin@fff9141

Tree-SHA512: 9fef617bceb74a1aec4f4a1e7c4732c4764af3e8ac2fc02b84ce370e8b97431957ca17ee8f44fb96765f7304f8d7e5bfb951440db98ba40f240612f2232d215e
@bitcoin bitcoin locked and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants