No description provided.
util: move MapIntoRange() for reuse in fuzz tests #23760
pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:reuse_mapintorange changing 3 files +31 −45-
fanquake commented at 12:57 PM on December 13, 2021: member
- MarcoFalke added the label Refactoring on Dec 13, 2021
-
sipa commented at 4:10 PM on December 13, 2021: member
This technique is actually used in a few other places in the codebase, though this is the only one that does it for 64-bit inputs and ranges; at least in
cache::compute_hashesincuckoocache.handFastModincommon/bloom.cpp. It's also used inbench/nanobench.h, but I think that file is intended to stay dependencyless.Perhaps it would make sense to have specific functions for both (e.g. FastRange32, FastRange64) and put them in an integer util file or so?
-
jamesob commented at 4:41 PM on December 13, 2021: member
Code review ACK https://github.com/bitcoin/bitcoin/pull/23760/commits/a8dc99f21cafaa8d37ea16bf9441872d5d653e09
Mergeable as it stands IMO, but what @sipa's saying probably makes sense too.
-
shaavan commented at 10:07 AM on December 14, 2021: contributor
Concept ACK
Moving the MapIntoRange allows both
src/blockfilter.cppandsrc/test/fuzz/golomb_rice.cppto access the function while removing unnecessary duplicated code.The one small thing that bugs me is using static keywords with the utility function. To be honest, I could not clearly understand the reasoning behind using (or not using) the static keyword with a utility function. Still, I had not seen many
src/utilfunctions with a static keyword in its definition.P.s.: I tried to comprehend the reasoning of static keyword, but I could not find a good reference for it. And I considered it is better to ask rather than to give an uninformed ACK.
-
MarcoFalke commented at 10:25 AM on December 14, 2021: member
I think using
staticin a header file is a way to embed the compiled function into every object file that uses it (as opposed to putting it into one object only and then linking that)? -
shaavan commented at 1:05 PM on December 15, 2021: contributor
embed the compiled function into every object file that uses it
So wouldn't it increase the memory used at runtime by the application? Is the speed boost provided by using
staticworth increasing memory usage? -
sipa commented at 2:01 PM on December 15, 2021: member
Using
statichere means that indeed, every compilation unit gets its own copy of the function. But, on the other hand, it means it doesn't need to be emitted either if all call-sites can be inlined (becausestaticfunctions are only accessible from within their own compilation unit; if there are no explicit calls left, the function doesn't need to be emitted), which is almost certainly the case. So the practical effect is really that it appears 0 times in the overall compilation output rather than 1 time. -
MarcoFalke commented at 2:05 PM on December 15, 2021: member
I guess changing
statictoinlinehere wouldn't change the binary, but clarify the intent a bit more? -
sipa commented at 2:08 PM on December 15, 2021: member
It could change the binary. Marking it
inlinebut notstaticmeans the compiler still has to emit it.-ffunction-sectionsand-Wl,--gc-sectionswill let the linker remove it, though.I think it should be both
inlineandstatic. -
shaavan commented at 7:09 AM on December 16, 2021: contributor
I think it should be both
inlineandstatic.As far as I understand the usage of static and inline, I think it's best to go with this solution.
-
util: move MapIntoRange() for reuse in fuzz tests df2307cdc3
- fanquake force-pushed on Dec 23, 2021
-
fanquake commented at 7:26 AM on December 23, 2021: member
I think it should be both inline and static.
Updated to be
static inline. -
MarcoFalke commented at 7:28 AM on December 23, 2021: member
See also the feedback here: #23760 (comment)
- shaavan approved
-
shaavan commented at 11:41 AM on December 23, 2021: contributor
ACK df2307cdc3d08233d17beb9a50c144baaef1f44e
Changes since my last review:
static->static inline
The rationale for the change is discussed above, with which I agree.
Going to leave that for now. Happy for someone else to follow up.
#23760 (comment) seems interesting. Let me try working upon it, and give an update as soon as possible.
- MarcoFalke merged this on Jan 6, 2022
- MarcoFalke closed this on Jan 6, 2022
- sidhujag referenced this in commit 837b427fe2 on Jan 6, 2022
- PastaPastaPasta referenced this in commit dfbcaf77a3 on Jul 17, 2022
- PastaPastaPasta referenced this in commit 4c1e9afc55 on Aug 30, 2022
- bitcoin locked this on Jan 6, 2023
- fanquake deleted the branch on Sep 14, 2023