-
Notifications
You must be signed in to change notification settings - Fork 0
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
Investigate the need to cache #2
Comments
Following this comment, here a patch I used to profile diff --git a/lua/mini/snippets.lua b/lua/mini/snippets.lua
index 8dafaef..59ba88d 100644
--- a/lua/mini/snippets.lua
+++ b/lua/mini/snippets.lua
@@ -993,11 +993,19 @@ end
---
---@return ... Array of snippets and supplied context (default if none was supplied).
MiniSnippets.default_prepare = function(raw_snippets, opts)
+ local start_time = vim.loop.hrtime()
if not H.islist(raw_snippets) then H.error('`raw_snippets` should be array') end
opts = vim.tbl_extend('force', { context = nil }, opts or {})
local context = opts.context
if context == nil then context = H.get_default_context() end
+ local cache_id = context.buf_id .. context.lang
+ if H.prepare_cache[cache_id] then
+ table.insert(_G.durations, 0.000001 * (vim.loop.hrtime() - start_time))
+ return unpack(H.prepare_cache[cache_id])
+ end
+
-- Traverse snippets to have unique non-empty prefixes
local res = {}
H.traverse_raw_snippets(raw_snippets, res, context)
@@ -1005,9 +1013,14 @@ MiniSnippets.default_prepare = function(raw_snippets, opts)
-- Convert to array ordered by prefix
res = vim.tbl_values(res)
table.sort(res, function(a, b) return a.prefix < b.prefix end)
+ H.prepare_cache[cache_id] = { res, context }
+ table.insert(_G.durations, 0.000001 * (vim.loop.hrtime() - start_time))
return res, context
end
+H.prepare_cache = {}
+_G.durations = {}
+
--- Default match
---
--- Match snippets based on the line before cursor. With benchmarking code present, open a separate Adding benchmarking code and then actually interactively performing the task to be benchmarked is usually a more accurate way of measuring things. |
Use caching in the same way as implemented in this |
In cmp-luasnip, a cache is maintained by ft, both for snippets and docs. That might very well be done for performance reasons. Otherwise, perhaps because LuaSnips supports snippets to be dynamically added/changed?
On each completion, all snippets do need to be transformed into results for nvim-cmp.... I am still unsure if caching should be added.
See this answer from
echasnovski
The text was updated successfully, but these errors were encountered: