feat: improve (?) performance of default sorter
This commit is contained in:
@@ -77,26 +77,28 @@ sorters.get_fuzzy_file = function(opts)
|
|||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local ngram_len = opts.ngram_len or 2
|
local ngram_len = opts.ngram_len or 2
|
||||||
local os_sep = '/'
|
local os_sep = util.get_separator()
|
||||||
|
local match_string = '[^' .. os_sep .. ']*$'
|
||||||
|
|
||||||
local cached_tails = setmetatable({}, {
|
local cached_tails = setmetatable({}, {
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
local tail_split = vim.split(k, os_sep)
|
local tail = string.match(k, match_string)
|
||||||
local tail = tail_split[#tail_split]
|
|
||||||
|
|
||||||
rawset(t, k, tail)
|
rawset(t, k, tail)
|
||||||
return tail
|
return tail
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- TODO: Consider either a faster way of getting these
|
||||||
|
-- OR we really should just cache them longer
|
||||||
|
-- OR we need a different way of keeping track of uppercase letters.
|
||||||
local cached_uppers = setmetatable({}, {
|
local cached_uppers = setmetatable({}, {
|
||||||
__index = function(t, k)
|
__index = function(t, k)
|
||||||
local obj = {}
|
local obj = {}
|
||||||
for i = 1, #k do
|
for i = 1, #k do
|
||||||
local s = k:sub(i, i)
|
local s_byte = k:byte(i, i)
|
||||||
local s_byte = s:byte()
|
|
||||||
if s_byte <= 90 and s_byte >= 65 then
|
if s_byte <= 90 and s_byte >= 65 then
|
||||||
obj[s] = true
|
obj[s_byte] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
71
lua/tests/manual/profile_for_sorters.lua
Normal file
71
lua/tests/manual/profile_for_sorters.lua
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
-- TODO: Add a ladder test.
|
||||||
|
-- 1, 2, 4, 8, 16, 32 attempts
|
||||||
|
|
||||||
|
RELOAD('plenary')
|
||||||
|
-- RELOAD('telescope')
|
||||||
|
|
||||||
|
local profiler = require('plenary.profile.lua_profiler')
|
||||||
|
local Job = require('plenary.job')
|
||||||
|
|
||||||
|
BIG_LIST = nil
|
||||||
|
BIG_LIST = BIG_LIST or Job:new { command = 'fdfind', cwd = '~/build/' }:sync()
|
||||||
|
print(#BIG_LIST)
|
||||||
|
|
||||||
|
local do_profile = true
|
||||||
|
local sorter_to_test = require('telescope.sorters').get_fuzzy_file()
|
||||||
|
|
||||||
|
local strings_to_test = { "", "ev", "eval.c", "neovim/eval.c" }
|
||||||
|
|
||||||
|
if do_profile then
|
||||||
|
profiler.start()
|
||||||
|
end
|
||||||
|
|
||||||
|
local first_results = setmetatable({}, {
|
||||||
|
__index = function(t, k)
|
||||||
|
local obj = {}
|
||||||
|
rawset(t, k, obj)
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
local second_results = {}
|
||||||
|
|
||||||
|
local do_iterations = function(num)
|
||||||
|
local start
|
||||||
|
for _, prompt in ipairs(strings_to_test) do
|
||||||
|
start = vim.fn.reltime()
|
||||||
|
|
||||||
|
for _ = 1, num do
|
||||||
|
for _, v in ipairs(BIG_LIST) do
|
||||||
|
sorter_to_test:score(prompt, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- print("First Time: ", vim.fn.reltimestr(vim.fn.reltime(start)), num, prompt)
|
||||||
|
table.insert(first_results[prompt], vim.fn.reltimestr(vim.fn.reltime(start)))
|
||||||
|
|
||||||
|
start = vim.fn.reltime()
|
||||||
|
for _ = 1, num do
|
||||||
|
for _, v in ipairs(BIG_LIST) do
|
||||||
|
sorter_to_test:score(prompt, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- print("Second Time: ", vim.fn.reltimestr(vim.fn.reltime(start)), num, prompt)
|
||||||
|
table.insert(second_results, vim.fn.reltimestr(vim.fn.reltime(start)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
do_iterations(1)
|
||||||
|
-- do_iterations(2)
|
||||||
|
-- do_iterations(4)
|
||||||
|
-- do_iterations(8)
|
||||||
|
-- do_iterations(16)
|
||||||
|
-- do_iterations(32)
|
||||||
|
|
||||||
|
print(vim.inspect(first_results))
|
||||||
|
|
||||||
|
if do_profile then
|
||||||
|
profiler.stop()
|
||||||
|
profiler.report('/home/tj/tmp/profiler_score.txt')
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user