Browse Source

json_add_hex: wire in at a lower level.

This is one of the more significant fields we print, but there's no
need to allocate a temp buffer or escape the resulting string.

MCP results from 5 runs, min-max(mean +/- stddev):
	store_load_msec:34048-36002(35070.4+/-8.5e+02)
	vsz_kb:2637488
	store_rewrite_sec:35.110000-38.120000(36.604+/-1.2)
	listnodes_sec:0.830000-1.020000(0.95+/-0.065)
	listchannels_sec:48.560000-55.680000(52.642+/-2.7)
	routing_sec:29.800000-33.170000(30.536+/-1.3)
	peer_write_all_sec:49.260000-52.490000(50.316+/-1.1)

MCP notable changes from previous patch (>1 stddev):
	-listchannels_sec:55.390000-58.110000(56.998+/-0.99)
	+listchannels_sec:48.560000-55.680000(52.642+/-2.7)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pr-2587
Rusty Russell 6 years ago
committed by neil saitug
parent
commit
465065691f
  1. 10
      lightningd/json.c
  2. 18
      lightningd/json_stream.c

10
lightningd/json.c

@ -330,16 +330,6 @@ void json_add_null(struct json_stream *stream, const char *fieldname)
json_add_member(stream, fieldname, "null");
}
void json_add_hex(struct json_stream *result, const char *fieldname,
const void *data, size_t len)
{
char *hex = tal_arr(NULL, char, hex_str_size(len));
hex_encode(data, len, hex, hex_str_size(len));
json_add_string(result, fieldname, hex);
tal_free(hex);
}
void json_add_hex_talarr(struct json_stream *result,
const char *fieldname,
const tal_t *data)

18
lightningd/json_stream.c

@ -1,6 +1,7 @@
#include <ccan/io/io.h>
/* To reach into io_plan: not a public header! */
#include <ccan/io/backend.h>
#include <ccan/str/hex/hex.h>
#include <common/utils.h>
#include <lightningd/json.h>
#include <lightningd/json_stream.h>
@ -271,6 +272,23 @@ json_add_member(struct json_stream *js, const char *fieldname,
va_end(ap);
}
void json_add_hex(struct json_stream *js, const char *fieldname,
const void *data, size_t len)
{
/* Size without NUL term */
size_t hexlen = hex_str_size(len) - 1;
char *dest;
json_start_member(js, fieldname);
mkroom(js, 1 + hexlen + 1);
dest = membuf_add(&js->outbuf, 1 + hexlen + 1);
dest[0] = '"';
if (!hex_encode(data, len, dest + 1, hexlen + 1))
abort();
dest[1+hexlen] = '"';
js_written_some(js);
}
/* This is where we read the json_stream and write it to conn */
static struct io_plan *json_stream_output_write(struct io_conn *conn,
struct json_stream *js)

Loading…
Cancel
Save