diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-01-02 15:47:55 +0000 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-01-03 19:17:52 +0000 |
commit | 3734519e3b4ba1bf19ca772104170b0ef776be46 (patch) | |
tree | 33ef73759201265fe99b5c0499d7f792a855aef0 /runtime/lua/vim/version.lua | |
parent | a064ed622927b4c5e30165abbe54db841359c71f (diff) | |
download | rneovim-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/version.lua')
-rw-r--r-- | runtime/lua/vim/version.lua | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua index 306eef90d3..0873402e29 100644 --- a/runtime/lua/vim/version.lua +++ b/runtime/lua/vim/version.lua @@ -158,7 +158,7 @@ end function M._version(version, strict) -- Adapted from https://github.com/folke/lazy.nvim if type(version) == 'table' then if version.major then - return setmetatable(vim.deepcopy(version), Version) + return setmetatable(vim.deepcopy(version, true), Version) end return setmetatable({ major = version[1] or 0, @@ -228,7 +228,7 @@ function VersionRange:has(version) version = M.parse(version) elseif getmetatable(version) ~= Version then -- Need metatable to compare versions. - version = setmetatable(vim.deepcopy(version), Version) + version = setmetatable(vim.deepcopy(version, true), Version) end if version then if version.prerelease ~= self.from.prerelease then @@ -298,7 +298,7 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim local semver = M.parse(version) if semver then local from = semver - local to = vim.deepcopy(semver) + local to = vim.deepcopy(semver, true) if mods == '' or mods == '=' then to.patch = to.patch + 1 elseif mods == '<' then |