perf: Filters:custom calls getcwd for every file, even with no custom filters

未关闭
#3,386 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@hood 已经在做这个了。

开始于 2026年11月5日。

  • #3387 来自 @hood —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
lua, neovim
领域
performance

调研方向

Start with lua/nvim-tree/explorer/filters.lua, especially Filters:custom and Filters:prepare; the issue identifies the repeated vim.uv.cwd() call and proposes resolving it once per directory only when custom patterns exist. Check the existing filtering tests and add coverage for empty and nonempty custom patterns. Done when filtering behavior stays the same and the unnecessary cwd calls are avoided; pull request #3387 is already open for this issue.

由索引模型根据 Issue 内容生成。

描述

Problem

Filters:custom calls vim.uv.cwd() for every file that gets scanned, via utils.path_relative(path, vim.uv.cwd()) (lua/nvim-tree/explorer/filters.lua:180). This happens even when filters.custom is empty, the default, so the result is never used.

getcwd is slow on some platforms: about 61µs per call on macOS.

Impact (profile on master)

Operation Share of time on this line
api.tree.expand_all() 33%
Explorer:reload_explorer() 42%

Proposed fix

  • Return early from Filters:custom when there are no custom patterns.
  • Resolve the cwd once per directory in Filters:prepare, and only when there are custom patterns.

Filtering behaviour stays the same.

Happy to follow up with a PR as soon as I get some time.

Environment: macOS, Nvim v0.13.0-dev, LuaJIT 2.1. Test repo: 16.8k files and folders, 3.1k git status entries (modified, untracked, ignored). Measured headless with vim.uv.hrtime() and the LuaJIT profiler (jit.p).

主要语言
Lua
星标
8.7k
派生
642
平均合并
1 天 4 分钟
30 天内合并 PR
11

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nvim-tree/nvim-tree.lua 的其他 Issue

查看 nvim-tree/nvim-tree.lua 的全部 Issue

相似的 Issue

更多 Lua Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。