neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 9005ffbe7757eca8ad809c81db76aec930db8e68
parent 8ef03188e68cc81bcb6a630a20451090c9557a98
Author: bfredl <bjorn.linse@gmail.com>
Date:   Tue,  3 May 2022 21:11:10 +0200

Merge pull request #18398 from vigoux/perf/ts_reuse_list

perf(treesitter): use a reuse list for query cursors
Diffstat:
Msrc/nvim/lua/treesitter.c | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c @@ -16,6 +16,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/buffer.h" +#include "nvim/lib/kvec.h" #include "nvim/lua/treesitter.h" #include "nvim/memline.h" #include "tree_sitter/api.h" @@ -104,6 +105,7 @@ static struct luaL_Reg treecursor_meta[] = { { NULL, NULL } }; +static kvec_t(TSQueryCursor *) cursors = KV_INITIAL_VALUE; static PMap(cstr_t) langs = MAP_INIT; static void build_meta(lua_State *L, const char *tname, const luaL_Reg *meta) @@ -1116,9 +1118,13 @@ static int node_rawquery(lua_State *L) return 0; } TSQuery *query = query_check(L, 2); - // TODO(bfredl): these are expensive allegedly, - // use a reuse list later on? - TSQueryCursor *cursor = ts_query_cursor_new(); + + TSQueryCursor *cursor; + if (kv_size(cursors) > 0) { + cursor = kv_pop(cursors); + } else { + cursor = ts_query_cursor_new(); + } // TODO(clason): API introduced after tree-sitter release 0.19.5 // remove guard when minimum ts version is bumped to 0.19.6+ #ifdef NVIM_TS_HAS_SET_MATCH_LIMIT @@ -1161,7 +1167,8 @@ static int node_rawquery(lua_State *L) static int querycursor_gc(lua_State *L) { TSLua_cursor *ud = luaL_checkudata(L, 1, TS_META_QUERYCURSOR); - ts_query_cursor_delete(ud->cursor); + kv_push(cursors, ud->cursor); + ud->cursor = NULL; return 0; }