Skip to content

Conversation

jonatack
Copy link
Member

where all the other logging actions in src/net.{h,cpp} are located.

StartExtraBlockRelayPeers() does not appear to be a hotspot that needs to be inlined for performance, as it is called from CheckForStaleTipAndEvictPeers(), called in turn from StartScheduledTasks() with a scheduleEvery delta of 45 seconds, called at the end of AppInitMain() on bitcoind startup.

This allows dropping #include <logging.h> from net.h, which can improve compile time/speed. Currently, none of the other includes in net.h use logging.h, except src/sync.h if DEBUG_LOCKCONTENTION is defined.

where all the other logging actions in src/net.{h,cpp} are located.

StartExtraBlockRelayPeers() does not appear to be a hotspot that needs to be
inlined for performance, as it is called from CheckForStaleTipAndEvictPeers(),
called in turn from StartScheduledTasks() with a scheduleEvery delta of 45
seconds, called at the end of AppInitMain() on bitcoind startup.

This allows dropping `#include <logging.h>` from net.h, which can improve
compile time/speed. Currently, none of the other includes in net.h use
logging.h, except src/sync.h if DEBUG_LOCKCONTENTION is defined.
@jonatack
Copy link
Member Author

Note: src/net.cpp is missing quite a few headers, including logging.h --- e0f804a adds them but I didn't include it in this pull unless people prefer it to be added.

@theStack
Copy link
Contributor

Concept ACK

Note: src/net.cpp is missing quite a few headers, including logging.h --- e0f804a adds them but I didn't include it in this pull unless people prefer it to be added.

Is this commit part of another PR? Github says "This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository." (but it must belong to this repository, otherwise the link wouldn't work right? :D)

@jonatack
Copy link
Member Author

jonatack commented May 12, 2022

Thanks for having a look! That homeless-looking commit was previously part of #24757, as a leftover from #24734.

@DrahtBot DrahtBot added the P2P label May 12, 2022
@LarryRuane
Copy link
Contributor

Just so I understand (and may be helpful to others), this PR compiles as is, but net.cpp makes use of some std libraries (for example, chrono) whose headers it doesn't include, but which happen to be included by other headers (that net.cpp is including). As opposed to net.cpp including everything it needs (that is, adding e0f804a to this PR, or wouldn't have to be this PR I guess).

As is (without this other commit), net.cpp compiles, but it may not in the future if one of the headers it includes stops including (for example) chrono, which net.cpp uses. In contrast, if that commit is merged, then net.cpp is more resilient to changes outside of itself (changes in other header files). The downside of adding those includes is that compiling is slower (even though they're just redundant includes so not that bad).

I'm probably not explaining this well, making it more complicated than it is, but do I have this right?

If so, my opinion is that it would be good to add that commit, but I don't feel strongly either way.

Copy link
Contributor

@LarryRuane LarryRuane left a comment

Choose a reason for hiding this comment

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

ACK 51ec96b
will re-ack if you decide to include the extra commit

@jonatack
Copy link
Member Author

@LarryRuane thanks! that seems right to me (IIUC, building isn't slower by including what you use, as otherwise it just wouldn't compile). I'll run iwyu on that commit to double-check and maybe add it.

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.

ACK 51ec96b

my opinion is that it would be good to add that commit, but I don't feel strongly either way.

+1, happy to re-review (either in this PR or a follow-up PR)

@@ -13,7 +13,6 @@
#include <crypto/siphash.h>
#include <hash.h>
#include <i2p.h>
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated, but:

net.h should add these lines:
#include <assert.h>            // for assert
#include <stddef.h>            // for size_t
#include <algorithm>           // for max, min
#include <chrono>              // for seconds, microseconds, operator""s
#include <set>                 // for set
#include <string>              // for string, basic_string, operator<
#include <utility>             // for move
#include "threadsafety.h"      // for GUARDED_BY, EXCLUSIVE_LOCKS_REQUIRED
#include "version.h"           // for INIT_PROTO_VERSION
class CChainParams;
class NetGroupManager;
class Sock;
namespace i2p::sam { class Session; }

net.h should remove these lines:
- #include <chainparams.h>  // lines 9-9
- #include <common/bloom.h>  // lines 10-10
- #include <consensus/amount.h>  // lines 12-12
- #include <i2p.h>  // lines 15-15
- #include <netgroup.h>  // lines 20-20
- #include <policy/feerate.h>  // lines 21-21
- #include <util/sock.h>  // lines 30-30
- class CNodeStats;  // lines 102-102

Copy link
Member Author

Choose a reason for hiding this comment

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

@MarcoFalke thanks. I ran iwyu python tool on src/net.{h,cpp} with the following (LMK if that incantation can be improved or how you are running it): python3 <path-to>/iwyu_tool src/net.cpp -p . -j5 -- -Xiwyu --cxx17ns -Xiwyu --mapping_file=<path-to>/contrib/devtools/iwyu/bitcoin.core.imp

and this was its output for me

net.h should add these lines:
#include <assert.h>            // for assert
#include <stddef.h>            // for size_t
#include <algorithm>           // for min
#include <chrono>              // for seconds, microseconds, operator""s
#include <set>                 // for set
#include <string>              // for string, operator<=>
#include <utility>             // for move
#include "threadsafety.h"      // for GUARDED_BY, EXCLUSIVE_LOCKS_REQUIRED
#include "tinyformat.h"        // for format_error
#include "version.h"           // for INIT_PROTO_VERSION
class CChainParams;
class NetGroupManager;
class Sock;
namespace i2p::sam { class Session; }

net.h should remove these lines:
- #include <chainparams.h>  // lines 9-9
- #include <common/bloom.h>  // lines 10-10
- #include <consensus/amount.h>  // lines 12-12
- #include <i2p.h>  // lines 15-15
- #include <netgroup.h>  // lines 19-19
- #include <policy/feerate.h>  // lines 20-20
- #include <util/sock.h>  // lines 29-29
- class CNodeStats;  // lines 101-101
net.cpp should add these lines:
#include <net/if.h>                 // for IFF_UP
#include <netinet/in.h>             // for htonl, IPV6_V6ONLY, in_addr, IN6A...
#include <netinet/tcp.h>            // for TCP_NODELAY
#include <string.h>                 // for memcpy, memcmp, strcmp
#include <sys/sdt.h>                // for __sdt_type, _SDT_ASM_OPERANDS_6
#include <sys/socket.h>             // for size_t, sockaddr_storage, bind
#include <compare>                  // for operator>, operator<, strong_orde...
#include <exception>                // for exception
#include <iterator>                 // for back_insert_iterator, back_inserter
#include <ratio>                    // for ratio
#include <tuple>                    // for tie, tuple
#include "chainparams.h"            // for Params, CChainParams
#include "crypto/common.h"          // for ReadLE32
#include "crypto/siphash.h"         // for CSipHasher
#include "hash.h"                   // for Hash, CHash256
#include "logging.h"                // for LogPrintf_, LogPrint, NET, LogPrintf
#include "netgroup.h"               // for NetGroupManager
#include "prevector.h"              // for prevector
#include "serialize.h"              // for SER_NETWORK, ser_writedata32, ser...
#include "span.h"                   // for Span, AsBytes, MakeByteSpan
#include "streams.h"                // for CDataStream, CAutoFile, CVectorWr...
#include "sync.h"                   // for LOCK, AssertLockNotHeldInternal
#include "threadinterrupt.h"        // for CThreadInterrupt
#include "timedata.h"               // for GetAdjustedTime
#include "util/time.h"              // for GetTime, count_seconds, GetTimeMi...

net.cpp should remove these lines:
- #include <crypto/sha256.h>  // lines 18-18
- #include <fcntl.h>  // lines 40-40
- #include <math.h>  // lines 58-58

@maflcko maflcko merged commit b3f0a34 into bitcoin:master May 13, 2022
@jonatack jonatack deleted the move-StartExtraBlockRelayPeers-from-header-to-implementation branch May 13, 2022 08:05
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 13, 2022
…from header to implementation

51ec96b refactor: move StartExtraBlockRelayPeers from header to implementation (Jon Atack)

Pull request description:

  where all the other logging actions in src/net.{h,cpp} are located.

  StartExtraBlockRelayPeers() does not appear to be a hotspot that needs to be inlined for performance, as it is called from CheckForStaleTipAndEvictPeers(), called in turn from StartScheduledTasks() with a scheduleEvery delta of 45 seconds, called at the end of AppInitMain() on bitcoind startup.

  This allows dropping `#include <logging.h>` from net.h, which can improve compile time/speed. Currently, none of the other includes in net.h use logging.h, except src/sync.h if DEBUG_LOCKCONTENTION is defined.

ACKs for top commit:
  LarryRuane:
    ACK 51ec96b
  theStack:
    ACK 51ec96b

Tree-SHA512: 69b2c09163c48bfcb43355af0aa52ee7dd81efc755a7aa6a10f5e400b5e14109484437960a62a1cfac2524c2cfae981fee082846b19526b540ef5b86be97f0fe
@bitcoin bitcoin locked and limited conversation to collaborators May 13, 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.

5 participants