Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON optimizations, cleanups and listsendpays optimizations #3957

Merged
merged 10 commits into from
Aug 21, 2020
16 changes: 9 additions & 7 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,11 @@ static bool rpc_read_response_one(struct plugin *plugin)
bool valid;
const jsmntok_t *toks, *jrtok;

/* FIXME: This could be done more efficiently by storing the
* toks and doing an incremental parse, like lightning-cli
* does. */
/* For our convenience, lightningd always ends JSON requests with
ZmnSCPxj marked this conversation as resolved.
Show resolved Hide resolved
* \n\n. We can abuse that as an optimization here.*/
if (!memmem(plugin->rpc_buffer, plugin->rpc_used, "\n\n", 2))
return false;

toks = json_parse_input(NULL, plugin->rpc_buffer, plugin->rpc_used,
&valid);
if (!toks) {
Expand Down Expand Up @@ -681,10 +683,10 @@ static bool rpc_read_response_one(struct plugin *plugin)

handle_rpc_reply(plugin, toks);

/* Move this object out of the buffer */
memmove(plugin->rpc_buffer, plugin->rpc_buffer + toks[0].end,
tal_count(plugin->rpc_buffer) - toks[0].end);
plugin->rpc_used -= toks[0].end;
/* Move this object out of the buffer (+ 2 for \n\n)*/
memmove(plugin->rpc_buffer, plugin->rpc_buffer + toks[0].end + 2,
tal_count(plugin->rpc_buffer) - toks[0].end - 2);
plugin->rpc_used -= toks[0].end + 2;
tal_free(toks);

return true;
Expand Down