Skip to content

Commit 63a2a8b

Browse files
committed
lightningd: use static buffer for common log path.
This speeds logging slightly, but most of the time is actually spent in fflush() (which we need). Result: FAILED tests/test_connection.py::test_bench - assert 51.54966354370117 == 0 Signed-off-by: Rusty Russell <[email protected]>
1 parent 2e4fa84 commit 63a2a8b

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lightningd/log.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ static void log_to_files(const char *log_prefix,
208208
{
209209
char tstamp[sizeof("YYYY-mm-ddTHH:MM:SS.nnnZ ")];
210210
char *entry, nodestr[hex_str_size(PUBKEY_CMPR_LEN)];
211+
char buf[sizeof("%s%s%s %s-%s: %s\n")
212+
+ strlen(log_prefix)
213+
+ sizeof(tstamp)
214+
+ strlen(level_prefix(level))
215+
+ sizeof(nodestr)
216+
+ strlen(entry_prefix)
217+
+ strlen(str)];
211218
bool filtered;
212219

213220
if (print_timestamps) {
@@ -235,14 +242,15 @@ static void log_to_files(const char *log_prefix,
235242
entry_prefix, str, dir, hex);
236243
tal_free(hex);
237244
} else {
245+
entry = buf;
238246
if (!node_id)
239-
entry = tal_fmt(tmpctx, "%s%s%s %s: %s\n",
240-
log_prefix, tstamp, level_prefix(level), entry_prefix, str);
247+
sprintf(buf, "%s%s%s %s: %s\n",
248+
log_prefix, tstamp, level_prefix(level), entry_prefix, str);
241249
else
242-
entry = tal_fmt(tmpctx, "%s%s%s %s-%s: %s\n",
243-
log_prefix, tstamp, level_prefix(level),
244-
nodestr,
245-
entry_prefix, str);
250+
sprintf(buf, "%s%s%s %s-%s: %s\n",
251+
log_prefix, tstamp, level_prefix(level),
252+
nodestr,
253+
entry_prefix, str);
246254
}
247255

248256
/* In complex configurations, we tell loggers to overshare: then we

0 commit comments

Comments
 (0)