Skip to content

Commit ddc3ec9

Browse files
author
MarcoFalke
committed
Merge #13634: ui: Compile boost::signals2 only once
fa5ce27 ui: Compile boost:signals2 only once (MarcoFalke) Pull request description: ui is one of the modules that poison other modules with `boost/signals2` headers. This moves the include to the cpp file and uses a forward declaration in the header. Locally this speeds up the incremental build (building everything that uses the ui module) with gcc by ~5% for me. Gcc uses ~5% less memory. Would be nice if someone could verify the numbers roughly. I presume the improvements will be more pronounced if the other models would stop exposing the boost header as well. Tree-SHA512: 078360eba330ddbca4268bd8552927eae242a239e18dfded25ec20be72650a68cd83af7ac160690249b943d33ae35d15df1313f1f60a0c28b9526853aa7d1e40
2 parents f87d0a9 + fa5ce27 commit ddc3ec9

File tree

5 files changed

+95
-34
lines changed

5 files changed

+95
-34
lines changed

src/init.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ static void registerSignalHandler(int signal, void(*handler)(int))
328328

329329
static void OnRPCStarted()
330330
{
331-
uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange);
331+
uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange);
332332
}
333333

334334
static void OnRPCStopped()
335335
{
336-
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
336+
uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange);
337337
RPCNotifyBlockChange(false, nullptr);
338338
g_best_block_cv.notify_all();
339339
LogPrint(BCLog::RPC, "RPC stopped.\n");
@@ -1287,7 +1287,7 @@ bool AppInitMain()
12871287
*/
12881288
if (gArgs.GetBoolArg("-server", false))
12891289
{
1290-
uiInterface.InitMessage.connect(SetRPCWarmupStatus);
1290+
uiInterface.InitMessage_connect(SetRPCWarmupStatus);
12911291
if (!AppInitServers())
12921292
return InitError(_("Unable to start HTTP server. See debug log for details."));
12931293
}
@@ -1644,13 +1644,13 @@ bool AppInitMain()
16441644
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
16451645
// No locking, as this happens before any background thread is started.
16461646
if (chainActive.Tip() == nullptr) {
1647-
uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait);
1647+
uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
16481648
} else {
16491649
fHaveGenesis = true;
16501650
}
16511651

16521652
if (gArgs.IsArgSet("-blocknotify"))
1653-
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
1653+
uiInterface.NotifyBlockTip_connect(BlockNotifyCallback);
16541654

16551655
std::vector<fs::path> vImportFiles;
16561656
for (const std::string& strFile : gArgs.GetArgs("-loadblock")) {
@@ -1668,7 +1668,7 @@ bool AppInitMain()
16681668
while (!fHaveGenesis && !ShutdownRequested()) {
16691669
condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500));
16701670
}
1671-
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
1671+
uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait);
16721672
}
16731673

16741674
if (ShutdownRequested()) {

src/interfaces/node.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,52 +233,52 @@ class NodeImpl : public Node
233233
}
234234
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
235235
{
236-
return MakeHandler(::uiInterface.InitMessage.connect(fn));
236+
return MakeHandler(::uiInterface.InitMessage_connect(fn));
237237
}
238238
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
239239
{
240-
return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn));
240+
return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn));
241241
}
242242
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
243243
{
244-
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn));
244+
return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn));
245245
}
246246
std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) override
247247
{
248-
return MakeHandler(::uiInterface.ShowProgress.connect(fn));
248+
return MakeHandler(::uiInterface.ShowProgress_connect(fn));
249249
}
250250
std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) override
251251
{
252252
CHECK_WALLET(
253-
return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
253+
return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr<CWallet> wallet) { fn(MakeWallet(wallet)); })));
254254
}
255255
std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
256256
{
257-
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn));
257+
return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn));
258258
}
259259
std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
260260
{
261-
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn));
261+
return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn));
262262
}
263263
std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
264264
{
265-
return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn));
265+
return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn));
266266
}
267267
std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
268268
{
269-
return MakeHandler(::uiInterface.BannedListChanged.connect(fn));
269+
return MakeHandler(::uiInterface.BannedListChanged_connect(fn));
270270
}
271271
std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
272272
{
273-
return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) {
273+
return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) {
274274
fn(initial_download, block->nHeight, block->GetBlockTime(),
275275
GuessVerificationProgress(Params().TxData(), block));
276276
}));
277277
}
278278
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
279279
{
280280
return MakeHandler(
281-
::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) {
281+
::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) {
282282
fn(initial_download, block->nHeight, block->GetBlockTime(),
283283
GuessVerificationProgress(Params().TxData(), block));
284284
}));

src/noui.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void noui_InitMessage(const std::string& message)
5252
void noui_connect()
5353
{
5454
// Connect bitcoind signal handlers
55-
uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox);
56-
uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion);
57-
uiInterface.InitMessage.connect(noui_InitMessage);
55+
uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
56+
uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
57+
uiInterface.InitMessage_connect(noui_InitMessage);
5858
}

src/ui_interface.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,60 @@
55
#include <ui_interface.h>
66
#include <util.h>
77

8+
#include <boost/signals2/last_value.hpp>
9+
#include <boost/signals2/signal.hpp>
10+
811
CClientUIInterface uiInterface;
912

13+
struct UISignals {
14+
boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::last_value<bool>> ThreadSafeMessageBox;
15+
boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::last_value<bool>> ThreadSafeQuestion;
16+
boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
17+
boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
18+
boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
19+
boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
20+
boost::signals2::signal<CClientUIInterface::LoadWalletSig> LoadWallet;
21+
boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
22+
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
23+
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
24+
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
25+
} g_ui_signals;
26+
27+
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
28+
boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
29+
{ \
30+
return g_ui_signals.signal_name.connect(fn); \
31+
} \
32+
void CClientUIInterface::signal_name##_disconnect(std::function<signal_name##Sig> fn) \
33+
{ \
34+
return g_ui_signals.signal_name.disconnect(&fn); \
35+
}
36+
37+
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox);
38+
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
39+
ADD_SIGNALS_IMPL_WRAPPER(InitMessage);
40+
ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
41+
ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged);
42+
ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
43+
ADD_SIGNALS_IMPL_WRAPPER(LoadWallet);
44+
ADD_SIGNALS_IMPL_WRAPPER(ShowProgress);
45+
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
46+
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
47+
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
48+
49+
bool CClientUIInterface::ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style); }
50+
bool CClientUIInterface::ThreadSafeQuestion(const std::string& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style); }
51+
void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
52+
void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
53+
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
54+
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
55+
void CClientUIInterface::LoadWallet(std::shared_ptr<CWallet> wallet) { return g_ui_signals.LoadWallet(wallet); }
56+
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
57+
void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(b, i); }
58+
void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); }
59+
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
60+
61+
1062
bool InitError(const std::string& str)
1163
{
1264
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);

src/ui_interface.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
#ifndef BITCOIN_UI_INTERFACE_H
77
#define BITCOIN_UI_INTERFACE_H
88

9+
#include <functional>
910
#include <memory>
1011
#include <stdint.h>
1112
#include <string>
1213

13-
#include <boost/signals2/last_value.hpp>
14-
#include <boost/signals2/signal.hpp>
15-
1614
class CWallet;
1715
class CBlockIndex;
16+
namespace boost {
17+
namespace signals2 {
18+
class connection;
19+
}
20+
} // namespace boost
1821

1922
/** General change type (added, updated, removed). */
2023
enum ChangeType
@@ -72,43 +75,49 @@ class CClientUIInterface
7275
MSG_ERROR = (ICON_ERROR | BTN_OK | MODAL)
7376
};
7477

78+
#define ADD_SIGNALS_DECL_WRAPPER(signal_name, rtype, args...) \
79+
rtype signal_name(args); \
80+
using signal_name##Sig = rtype(args); \
81+
boost::signals2::connection signal_name##_connect(std::function<signal_name##Sig> fn); \
82+
void signal_name##_disconnect(std::function<signal_name##Sig> fn);
83+
7584
/** Show message box. */
76-
boost::signals2::signal<bool (const std::string& message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeMessageBox;
85+
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const std::string& message, const std::string& caption, unsigned int style);
7786

7887
/** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, caption, style) and returns false. */
79-
boost::signals2::signal<bool (const std::string& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style), boost::signals2::last_value<bool> > ThreadSafeQuestion;
88+
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const std::string& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style);
8089

8190
/** Progress message during initialization. */
82-
boost::signals2::signal<void (const std::string &message)> InitMessage;
91+
ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message);
8392

8493
/** Number of network connections changed. */
85-
boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
94+
ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections);
8695

8796
/** Network activity state changed. */
88-
boost::signals2::signal<void (bool networkActive)> NotifyNetworkActiveChanged;
97+
ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive);
8998

9099
/**
91100
* Status bar alerts changed.
92101
*/
93-
boost::signals2::signal<void ()> NotifyAlertChanged;
102+
ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, );
94103

95104
/** A wallet has been loaded. */
96-
boost::signals2::signal<void (std::shared_ptr<CWallet> wallet)> LoadWallet;
105+
ADD_SIGNALS_DECL_WRAPPER(LoadWallet, void, std::shared_ptr<CWallet> wallet);
97106

98107
/**
99108
* Show progress e.g. for verifychain.
100109
* resume_possible indicates shutting down now will result in the current progress action resuming upon restart.
101110
*/
102-
boost::signals2::signal<void (const std::string &title, int nProgress, bool resume_possible)> ShowProgress;
111+
ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible);
103112

104113
/** New block has been accepted */
105-
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;
114+
ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, bool, const CBlockIndex*);
106115

107116
/** Best header has changed */
108-
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyHeaderTip;
117+
ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, bool, const CBlockIndex*);
109118

110119
/** Banlist did change. */
111-
boost::signals2::signal<void (void)> BannedListChanged;
120+
ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void);
112121
};
113122

114123
/** Show warning message **/

0 commit comments

Comments
 (0)