feat(performance): Major performance improvements using async v2 from @oberblastmeister (#987)
* start: Working w/ async jobs * short circuit to using bad finder if you pass writer.
This commit is contained in:
@@ -11,8 +11,13 @@ describe("telescope", function()
|
||||
end)
|
||||
|
||||
describe("attach_mappings", function()
|
||||
local new_picker = function(a, b)
|
||||
a.finder = true
|
||||
return picker.new(a, b)
|
||||
end
|
||||
|
||||
it("should allow for passing in a function", function()
|
||||
local p = picker.new({}, {
|
||||
local p = new_picker({}, {
|
||||
attach_mappings = function()
|
||||
return 1
|
||||
end,
|
||||
@@ -22,7 +27,7 @@ describe("telescope", function()
|
||||
|
||||
it("should override an attach mappings passed in by opts", function()
|
||||
local called_order = {}
|
||||
local p = picker.new({
|
||||
local p = new_picker({
|
||||
attach_mappings = function()
|
||||
table.insert(called_order, "opts")
|
||||
end,
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
--[[
|
||||
vim.api.nvim_buf_set_lines(0, 4, -1, false, vim.tbl_keys(require('telescope.builtin')))
|
||||
--]]
|
||||
|
||||
require("telescope.builtin").git_files()
|
||||
RELOAD "telescope"
|
||||
require("telescope.builtin").oldfiles()
|
||||
require("telescope.builtin").grep_string()
|
||||
require("telescope.builtin").lsp_document_symbols()
|
||||
RELOAD "telescope"
|
||||
require("telescope.builtin").lsp_workspace_symbols()
|
||||
require("telescope.builtin").lsp_references()
|
||||
require("telescope.builtin").builtin()
|
||||
require("telescope.builtin").fd()
|
||||
require("telescope.builtin").command_history()
|
||||
require("telescope.builtin").search_history()
|
||||
require("telescope.builtin").live_grep()
|
||||
require("telescope.builtin").loclist()
|
||||
|
||||
-- TODO: make a function that puts stuff into quickfix.
|
||||
-- that way we can test this better.
|
||||
require("telescope.builtin").quickfix()
|
||||
@@ -1,80 +0,0 @@
|
||||
RELOAD "telescope"
|
||||
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local find_files = function(opts)
|
||||
opts = opts or {}
|
||||
opts.prompt_prefix = ""
|
||||
|
||||
local find_command = opts.find_command
|
||||
|
||||
if not find_command then
|
||||
if 1 == vim.fn.executable "fd" then
|
||||
find_command = { "fd", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "fdfind" then
|
||||
find_command = { "fdfind", "--type", "f" }
|
||||
elseif 1 == vim.fn.executable "rg" then
|
||||
find_command = { "rg", "--files" }
|
||||
end
|
||||
end
|
||||
|
||||
if opts.cwd then
|
||||
opts.cwd = vim.fn.expand(opts.cwd)
|
||||
end
|
||||
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
local p = pickers.new(opts, {
|
||||
prompt = "Find Files",
|
||||
finder = finders.new_oneshot_job(find_command, opts),
|
||||
previewer = previewers.cat.new(opts),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
|
||||
track = true,
|
||||
})
|
||||
|
||||
local count = 0
|
||||
p:register_completion_callback(function(s)
|
||||
print(
|
||||
count,
|
||||
vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == "string" and item:sub(1, 1) == "_" then
|
||||
return nil
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
count = count + 1
|
||||
end)
|
||||
|
||||
local feed = function(text, feed_opts)
|
||||
feed_opts = feed_opts or "n"
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), feed_opts, true)
|
||||
end
|
||||
|
||||
p:register_completion_callback(coroutine.wrap(function()
|
||||
local input = "pickers.lua"
|
||||
for i = 1, #input do
|
||||
feed(input:sub(i, i))
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
vim.wait(300, function() end)
|
||||
feed("<CR>", "")
|
||||
|
||||
coroutine.yield()
|
||||
print "STILL CALLED?"
|
||||
end))
|
||||
|
||||
p:find()
|
||||
end
|
||||
|
||||
find_files()
|
||||
@@ -1,105 +0,0 @@
|
||||
require("plenary.reload").reload_module "plenary"
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
--[[
|
||||
|
||||
Goals:
|
||||
1. Easily test a sorter and finder to make sure we get all the results we need.
|
||||
|
||||
--]]
|
||||
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local EntryManager = require "telescope.entry_manager"
|
||||
|
||||
local find_and_sort_test = function(prompt, f, s)
|
||||
local info = {}
|
||||
|
||||
local start = vim.loop.hrtime()
|
||||
|
||||
info.filtered = 0
|
||||
info.added = 0
|
||||
info.scoring_time = 0
|
||||
info.set_entry = 0
|
||||
|
||||
local entry_manager = EntryManager:new(25, function()
|
||||
info.set_entry = info.set_entry + 1
|
||||
end, info)
|
||||
|
||||
local completed = false
|
||||
|
||||
local process_result = function(entry)
|
||||
local score_start = vim.loop.hrtime()
|
||||
local score = s:score(prompt, entry)
|
||||
info.scoring_time = info.scoring_time + (vim.loop.hrtime() - score_start) / 1e9
|
||||
|
||||
-- Filter these out here.
|
||||
if score == -1 then
|
||||
info.filtered = info.filtered + 1
|
||||
return
|
||||
end
|
||||
|
||||
info.added = info.added + 1
|
||||
entry_manager:add_entry(s:score(prompt, entry), entry)
|
||||
end
|
||||
|
||||
local process_complete = function()
|
||||
info.time = (vim.loop.hrtime() - start) / 1e9
|
||||
|
||||
info.total = info.filtered + info.added
|
||||
completed = true
|
||||
end
|
||||
|
||||
f(prompt, process_result, process_complete)
|
||||
|
||||
-- Wait until we're done to return
|
||||
vim.wait(5000, function()
|
||||
return completed
|
||||
end, 10)
|
||||
|
||||
return entry_manager, info
|
||||
end
|
||||
|
||||
local info_to_csv = function(info, filename)
|
||||
local writer = io.open(filename, "a")
|
||||
|
||||
writer:write(string.format("%.8f", info.scoring_time) .. "\t")
|
||||
writer:write(string.format("%.8f", info.time) .. "\t")
|
||||
writer:write(info.looped .. "\t")
|
||||
writer:write(info.filtered .. "\t")
|
||||
writer:write(info.added .. "\t")
|
||||
writer:write(info.inserted .. "\t")
|
||||
writer:write(info.total .. "\t")
|
||||
writer:write(info.set_entry .. "\t")
|
||||
writer:write(string.format("%.0f", collectgarbage "count") .. "\t")
|
||||
writer:write "\n"
|
||||
|
||||
writer:close()
|
||||
end
|
||||
|
||||
local cwd = vim.fn.expand "~/build/neovim"
|
||||
|
||||
collectgarbage "collect"
|
||||
for _ = 1, 1 do
|
||||
-- local s = sorters.get_fuzzy_file()
|
||||
local s = sorters.get_generic_fuzzy_sorter()
|
||||
local finder = finders.new_oneshot_job({ "fdfind" }, {
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file { cwd = cwd },
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
})
|
||||
|
||||
local res, info = find_and_sort_test("pickers.lua", finder, s)
|
||||
|
||||
-- print(vim.inspect(res:get_entry(1)))
|
||||
-- print(vim.inspect(info))
|
||||
|
||||
info_to_csv(info, "/home/tj/tmp/profile.csv")
|
||||
|
||||
collectgarbage "collect"
|
||||
end
|
||||
-- No skip: 2,206,186
|
||||
-- Ya skip: 2,133
|
||||
@@ -1,29 +0,0 @@
|
||||
RELOAD "plenary"
|
||||
RELOAD "telescope"
|
||||
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local cwd = vim.fn.expand "~/build/neovim"
|
||||
|
||||
pickers.new({
|
||||
prompt = "Large search",
|
||||
finder = finders.new_oneshot_job({ "fdfind" }, {
|
||||
cwd = cwd,
|
||||
entry_maker = make_entry.gen_from_file { cwd = cwd },
|
||||
-- disable_devicons = true,
|
||||
-- maximum_results = 1000,
|
||||
}),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
previewer = previewers.cat.new { cwd = cwd },
|
||||
}):find()
|
||||
|
||||
-- vim.wait(3000, function()
|
||||
-- vim.cmd [[redraw!]]
|
||||
-- return COMPLETED
|
||||
-- end, 100)
|
||||
-- vim.cmd [[bd!]]
|
||||
-- vim.cmd [[stopinsert]]
|
||||
@@ -1,24 +0,0 @@
|
||||
require("plenary.reload").reload_module "telescope"
|
||||
|
||||
local finders = require "telescope.finders"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local previewers = require "telescope.previewers"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
|
||||
local my_list = {
|
||||
"lua/telescope/WIP.lua",
|
||||
"lua/telescope/actions.lua",
|
||||
"lua/telescope/builtin.lua",
|
||||
}
|
||||
|
||||
local opts = {}
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt = "Telescope Builtin",
|
||||
finder = finders.new_table {
|
||||
results = my_list,
|
||||
},
|
||||
sorter = sorters.get_generic_fuzzy_sorter(),
|
||||
previewer = previewers.cat.new(opts),
|
||||
}):find()
|
||||
@@ -1,70 +0,0 @@
|
||||
-- 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
|
||||
@@ -1,50 +0,0 @@
|
||||
-- local actions = require('telescope.actions')
|
||||
-- local utils = require('telescope.utils')
|
||||
require "telescope"
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
|
||||
local log = require "telescope.log"
|
||||
|
||||
local real_opts = setmetatable({}, { __mode = "v" })
|
||||
local opts = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
log.debug("accessing:", k)
|
||||
return real_opts[k]
|
||||
end,
|
||||
__newindex = function(t, k, v)
|
||||
log.debug("setting:", k, v)
|
||||
real_opts[k] = v
|
||||
end,
|
||||
})
|
||||
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file()
|
||||
if opts.cwd then
|
||||
opts.cwd = vim.fn.expand(opts.cwd)
|
||||
end
|
||||
|
||||
-- local get_finder_opts = function(opts)
|
||||
-- local t = {}
|
||||
-- t.entry_maker = table.pop(opts, 'entry_maker')
|
||||
-- return t
|
||||
-- end
|
||||
|
||||
-- local finder_opts = get_finder_opts(opts)
|
||||
-- assert(not opts.entry_maker)
|
||||
|
||||
local picker_config = {
|
||||
prompt = "Git File",
|
||||
finder = finders.new_oneshot_job({ "git", "ls-files", "-o", "--exclude-standard", "-c" }, opts),
|
||||
-- previewer = previewers.cat.new(opts),
|
||||
-- sorter = sorters.get_fuzzy_file(opts),
|
||||
-- sorter = sorters.get_fuzzy_file(),
|
||||
}
|
||||
|
||||
log.debug "Done with config"
|
||||
|
||||
local x = pickers.new(picker_config)
|
||||
x:find()
|
||||
x = nil
|
||||
@@ -1,62 +0,0 @@
|
||||
RELOAD "telescope"
|
||||
|
||||
local resolve = require "telescope.config.resolve"
|
||||
|
||||
local eq = function(a, b)
|
||||
if a ~= b then
|
||||
error(string.format("Expected a == b, got: %s and %s", vim.inspect(a), vim.inspect(b)))
|
||||
end
|
||||
end
|
||||
|
||||
local opt = nil
|
||||
|
||||
local height_config = 0.8
|
||||
opt = resolve.win_option(height_config)
|
||||
|
||||
eq(height_config, opt.preview)
|
||||
eq(height_config, opt.prompt)
|
||||
eq(height_config, opt.results)
|
||||
|
||||
opt = resolve.win_option(nil, height_config)
|
||||
|
||||
eq(height_config, opt.preview)
|
||||
eq(height_config, opt.prompt)
|
||||
eq(height_config, opt.results)
|
||||
|
||||
local table_val = { "a" }
|
||||
opt = resolve.win_option(nil, table_val)
|
||||
eq(table_val, opt.preview)
|
||||
eq(table_val, opt.prompt)
|
||||
eq(table_val, opt.results)
|
||||
|
||||
local prompt_override = { "a", prompt = "b" }
|
||||
opt = resolve.win_option(prompt_override)
|
||||
eq("a", opt.preview)
|
||||
eq("a", opt.results)
|
||||
eq("b", opt.prompt)
|
||||
|
||||
local all_specified = { preview = "a", prompt = "b", results = "c" }
|
||||
opt = resolve.win_option(all_specified)
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
|
||||
local some_specified = { prompt = "b", results = "c" }
|
||||
opt = resolve.win_option(some_specified, "a")
|
||||
eq("a", opt.preview)
|
||||
eq("b", opt.prompt)
|
||||
eq("c", opt.results)
|
||||
|
||||
eq(10, resolve.resolve_height(0.1)(nil, 24, 100))
|
||||
eq(2, resolve.resolve_width(0.1)(nil, 24, 100))
|
||||
|
||||
eq(10, resolve.resolve_width(10)(nil, 24, 100))
|
||||
eq(24, resolve.resolve_width(50)(nil, 24, 100))
|
||||
|
||||
-- local true_table = {true}
|
||||
-- opt = resolve.win_option(some_specified, 'a')
|
||||
-- eq('a', opt.preview)
|
||||
-- eq('b', opt.prompt)
|
||||
-- eq('c', opt.results)
|
||||
|
||||
print "DONE!"
|
||||
@@ -1,70 +0,0 @@
|
||||
RELOAD "telescope"
|
||||
|
||||
local actions = require "telescope.actions"
|
||||
local finders = require "telescope.finders"
|
||||
local make_entry = require "telescope.make_entry"
|
||||
local previewers = require "telescope.previewers"
|
||||
local pickers = require "telescope.pickers"
|
||||
local sorters = require "telescope.sorters"
|
||||
local utils = require "telescope.utils"
|
||||
|
||||
local slow_proc = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
if opts.cwd then
|
||||
opts.cwd = vim.fn.expand(opts.cwd)
|
||||
end
|
||||
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
local p = pickers.new(opts, {
|
||||
prompt = "Slow Proc",
|
||||
finder = finders.new_oneshot_job({ "./scratch/slow_proc.sh" }, opts),
|
||||
previewer = previewers.cat.new(opts),
|
||||
sorter = sorters.get_fuzzy_file(),
|
||||
|
||||
track = true,
|
||||
})
|
||||
|
||||
local count = 0
|
||||
p:register_completion_callback(function(s)
|
||||
print(
|
||||
count,
|
||||
vim.inspect(s.stats, {
|
||||
process = function(item)
|
||||
if type(item) == "string" and item:sub(1, 1) == "_" then
|
||||
return nil
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
})
|
||||
)
|
||||
|
||||
count = count + 1
|
||||
end)
|
||||
|
||||
local feed = function(text)
|
||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(text, true, false, true), "n", true)
|
||||
end
|
||||
|
||||
if false then
|
||||
p:register_completion_callback(coroutine.wrap(function()
|
||||
local input = "pickers.lua"
|
||||
for i = 1, #input do
|
||||
feed(input:sub(i, i))
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
vim.wait(300, function() end)
|
||||
|
||||
vim.cmd [[:q]]
|
||||
vim.cmd [[:Messages]]
|
||||
vim.cmd [[stopinsert]]
|
||||
end))
|
||||
end
|
||||
|
||||
p:find()
|
||||
end
|
||||
|
||||
slow_proc()
|
||||
Reference in New Issue
Block a user