aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-01-02 15:47:55 +0000
committerLewis Russell <me@lewisr.dev>2024-01-03 19:17:52 +0000
commit3734519e3b4ba1bf19ca772104170b0ef776be46 (patch)
tree33ef73759201265fe99b5c0499d7f792a855aef0 /runtime/lua/vim/diagnostic.lua
parenta064ed622927b4c5e30165abbe54db841359c71f (diff)
downloadrneovim-3734519e3b4ba1bf19ca772104170b0ef776be46.tar.gz
rneovim-3734519e3b4ba1bf19ca772104170b0ef776be46.tar.bz2
rneovim-3734519e3b4ba1bf19ca772104170b0ef776be46.zip
feat(lua): add noref to deepcopy
Problem: Currently `deepcopy` hashes every single tables it copies so it can be reused. For tables of mostly unique items that are non recursive, this hashing is unnecessarily expensive Solution: Port the `noref` argument from Vimscripts `deepcopy()`. The below benchmark demonstrates the results for two extreme cases of tables of different sizes. One table that uses the same table lots of times and one with all unique tables. | test | `noref=false` (ms) | `noref=true` (ms) | | -------------------- | ------------------ | ----------------- | | unique tables (50) | 6.59 | 2.62 | | shared tables (50) | 3.24 | 6.40 | | unique tables (2000) | 23381.48 | 2884.53 | | shared tables (2000) | 3505.54 | 14038.80 | The results are basically the inverse of each other where `noref` is much more performance on tables with unique fields, and `not noref` is more performant on tables that reuse fields.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua12
1 files changed, 6 insertions, 6 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index a447463dff..897837a5ce 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -134,7 +134,7 @@ local function prefix_source(diagnostics)
return d
end
- local t = vim.deepcopy(d)
+ local t = vim.deepcopy(d, true)
t.message = string.format('%s: %s', d.source, d.message)
return t
end, diagnostics)
@@ -146,7 +146,7 @@ local function reformat_diagnostics(format, diagnostics)
diagnostics = { diagnostics, 't' },
})
- local formatted = vim.deepcopy(diagnostics)
+ local formatted = vim.deepcopy(diagnostics, true)
for _, diagnostic in ipairs(formatted) do
diagnostic.message = format(diagnostic)
end
@@ -373,7 +373,7 @@ local function get_diagnostics(bufnr, opts, clamp)
or d.col < 0
or d.end_col < 0
then
- d = vim.deepcopy(d)
+ d = vim.deepcopy(d, true)
d.lnum = math.max(math.min(d.lnum, line_count), 0)
d.end_lnum = math.max(math.min(d.end_lnum, line_count), 0)
d.col = math.max(d.col, 0)
@@ -636,7 +636,7 @@ function M.config(opts, namespace)
if not opts then
-- Return current config
- return vim.deepcopy(t)
+ return vim.deepcopy(t, true)
end
for k, v in pairs(opts) do
@@ -723,7 +723,7 @@ end
---
---@return table A list of active diagnostic namespaces |vim.diagnostic|.
function M.get_namespaces()
- return vim.deepcopy(all_namespaces)
+ return vim.deepcopy(all_namespaces, true)
end
---@class Diagnostic
@@ -756,7 +756,7 @@ function M.get(bufnr, opts)
opts = { opts, 't', true },
})
- return vim.deepcopy(get_diagnostics(bufnr, opts, false))
+ return vim.deepcopy(get_diagnostics(bufnr, opts, false), true)
end
--- Get current diagnostics count.