-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
Conversation
There was a problem hiding this 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:
Lines 44 to 48 in d0bf9bb
void static inline WriteLE32(unsigned char* ptr, uint32_t x) | |
{ | |
uint32_t v = htole32(x); | |
memcpy(ptr, (char*)&v, 4); | |
} |
Lines 77 to 81 in d0bf9bb
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.
Thanks for the suggestion. I update the following. |
src/bench/rollingbloom.cpp
Outdated
data[1] = (count >> 8) & 0xFF; | ||
data[2] = (count >> 16) & 0xFF; | ||
data[3] = (count >> 24) & 0xFF; | ||
for(int i = 0; i <= 3; i++){ |
There was a problem hiding this comment.
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);
.
src/bench/rollingbloom.cpp
Outdated
data[1] = (count >> 16) & 0xFF; | ||
data[2] = (count >> 8) & 0xFF; | ||
data[3] = count & 0xFF; | ||
for(int i = 3; i >= 0; i--){ |
There was a problem hiding this comment.
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);
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
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. |
Isn't this bit inefficient because we are actually dropping the whole content of |
Hey @sipa what's your views on this before making a function call ? |
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... |
oh , okay ! Then it's fine I think. |
Sorry for the direct commit , need to do some more changes. |
Hey, any update on this? |
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 |
Cool, will do that soon. Thanks! |
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? |
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/. |
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 ? |
@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 |
Your branch contains merge commits, which can't be squashed in a rebase. Something like this might work (untested!!):
|
I tried this , it seems more mess tho. |
After the steps in #24088 (comment) you need to force push, not merge |
Thank you sm @MarcoFalke . It seems like it works fine. |
There was a problem hiding this 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.
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. |
+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. |
I've just gone ahead and fixed this up in #24784, given this is straightforward, and likely been open long enough. |
…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
…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
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.