From 45bee1dafd0d4042f3b22928b5cc6021a1772bb7 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 25 Jun 2022 18:51:55 +0200 Subject: perf(ui): eliminate spurious memory allocations for hl_attr_define event --- src/nvim/api/private/helpers.h | 6 ++++++ src/nvim/api/ui.c | 17 +++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index a4348d8b44..224ce41aae 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -86,6 +86,12 @@ name.capacity = maxsize; \ name.items = name##__items; \ +#define MAXSIZE_TEMP_DICT(name, maxsize) \ + Dictionary name = ARRAY_DICT_INIT; \ + KeyValuePair name##__items[maxsize]; \ + name.capacity = maxsize; \ + name.items = name##__items; \ + #define cbuf_as_string(d, s) ((String) { .data = d, .size = s }) #define STATIC_CSTR_AS_STRING(s) ((String) { .data = s, .size = sizeof(s) - 1 }) diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 54ce838b9b..aa7bed1132 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -748,8 +748,10 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt UIData *data = ui->data; Array args = data->call_buf; ADD_C(args, INTEGER_OBJ(id)); - ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(rgb_attrs, true))); - ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(cterm_attrs, false))); + MAXSIZE_TEMP_DICT(rgb, 16); + MAXSIZE_TEMP_DICT(cterm, 16); + ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&rgb, rgb_attrs, true))); + ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&cterm, cterm_attrs, false))); if (ui->ui_ext[kUIHlState]) { ADD_C(args, ARRAY_OBJ(info)); @@ -758,9 +760,6 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt } push_call(ui, "hl_attr_define", args); - // TODO(bfredl): could be elided - api_free_dictionary(kv_A(args, 1).data.dictionary); - api_free_dictionary(kv_A(args, 2).data.dictionary); } static void remote_ui_highlight_set(UI *ui, int id) @@ -772,11 +771,9 @@ static void remote_ui_highlight_set(UI *ui, int id) return; } data->hl_id = id; - Dictionary hl = hlattrs2dict(syn_attr2entry(id), ui->rgb); - - ADD_C(args, DICTIONARY_OBJ(hl)); + MAXSIZE_TEMP_DICT(dict, 16); + ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb))); push_call(ui, "highlight_set", args); - api_free_dictionary(kv_A(args, 0).data.dictionary); } /// "true" cursor used only for input focus @@ -963,7 +960,7 @@ static Array translate_contents(UI *ui, Array contents) Array new_item = ARRAY_DICT_INIT; int attr = (int)item.items[0].data.integer; if (attr) { - Dictionary rgb_attrs = hlattrs2dict(syn_attr2entry(attr), ui->rgb); + Dictionary rgb_attrs = hlattrs2dict(NULL, syn_attr2entry(attr), ui->rgb); ADD(new_item, DICTIONARY_OBJ(rgb_attrs)); } else { ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT)); -- cgit From 0b63f5afad852d077bb430ad9c9ba4301980d500 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 29 Jun 2022 22:49:37 +0200 Subject: perf(ui): unpack grid_line (screen contents) directly --- src/nvim/api/private/defs.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/private/defs.h b/src/nvim/api/private/defs.h index b1e0dd364c..9c7e59e4b3 100644 --- a/src/nvim/api/private/defs.h +++ b/src/nvim/api/private/defs.h @@ -36,6 +36,7 @@ typedef enum { kMessageTypeRequest = 0, kMessageTypeResponse = 1, kMessageTypeNotification = 2, + kMessageTypeRedrawEvent = 3, } MessageType; /// Mask for all internal calls -- cgit From f87c8245133dd8116a9bab2d2e89f9b26967c7a8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 9 Jul 2022 14:48:09 +0200 Subject: fix(rpc): break nvim_error_event feedback loop between two nvim instances In case nvim A sends nvim_error_event to nvim B, it would respond with another nvim_error_event due to unknown request name. Fix this by adding dummy request handler for now. --- src/nvim/api/vim.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/api') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 56516b2ac7..5d941890db 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2256,3 +2256,11 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * return result; } + +void nvim_error_event(uint64_t channel_id, Integer lvl, String data) + FUNC_API_REMOTE_ONLY +{ + // TODO(bfredl): consider printing message to user, as will be relevant + // if we fork nvim processes as async workers + ELOG("async error on channel %" PRId64 ": %s", channel_id, data.size ? data.data : ""); +} -- cgit