commit 78bbe53f7615e8b38d5289d9ce0579996109579b
parent b87bdef2a8649ce40a8f722432934bef3d6d4b57
Author: Shmerl <shtetldik+shmerl@gmail.com>
Date: Wed, 10 Dec 2025 13:33:33 -0500
fix(vim.loader): randomized AppImage path pollutes luac cache #35636
Problem:
When using the Nvim appimage, `~/.cache/nvim/luac` directory can grow to
250,000+ files.
Example of 2 identical files in `./luac/`:
%2ftmp%2f.mount_nvim.a65Rja0%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac
%2ftmp%2f.mount_nvim.aNpxXgo%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac
Analysis:
The `nvim.appimage` mounts nvim at a different temporary path each time
it is invoked. The naming scheme of these cache files is random, which
defats the purpose of the cache creates N new files on every launch of
nvim.
Steps to reproduce:
1. install `nvim.appimage`
2. `mv ~/.cache/nvim/luac ~/.cache/nvim/luac.backup`
3. `nvim`
4. Observe contents of `~/.cache/nvim/luac/`
5. Close nvim and run `nvim` again
6. Observe contents of `~/.cache/nvim/luac/` and see that new identical
files have been added with a different mount prefix
Solution:
When running from an appimage, trim the random part of the filepaths.
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
@@ -7,6 +7,7 @@ local loaders = package.loaders
local _loadfile = loadfile
local VERSION = 4
+local is_appimage = (os.getenv('APPIMAGE') ~= nil)
local M = {}
@@ -78,7 +79,15 @@ local function fs_stat_cached(path)
end
local function normalize(path)
- return fs.normalize(path, { expand_env = false, _fast = true })
+ path = fs.normalize(path, { expand_env = false, _fast = true })
+
+ if is_appimage then
+ -- Avoid cache pollution caused by AppImage randomizing the program root. #31165
+ -- "/tmp/.mount_nvimAmpHPH/usr/share/nvim/runtime" => "/usr/share/nvim/runtime"
+ path = path:match('(/usr/.*)') or path
+ end
+
+ return path
end
local rtp_cached = {} --- @type string[]