perf: renderer highlights via vim.hl.range are slow on large trees

未关闭 适合新手
#3,381 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
lua

调研方向

从 Renderer:render_hl 开始,追踪它如何应用单行字节范围和优先级。将现有的 vim.hl.range 调用与使用 vim.hl.priorities.user 的 nvim_buf_set_extmark 进行比较;验证最终的高亮效果完全一致,并对大型树上的渲染进行基准测试。当直接调用 extmark 保持相同的范围、优先级和外观,同时缩短渲染时间时,任务即告完成。

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

描述

Problem

Renderer:render_hl applies every highlight of every line with vim.hl.range. That function is generic: on each call it switches buffer context with vim._with, calls col('$') twice and calls getregionpos. nvim-tree's ranges are always single-line byte ranges, so none of that work is needed.

Impact

µs per highlight
vim.hl.range 6.1
nvim_buf_set_extmark 0.74

At 16.8k visible lines, render_hl is about 50% of Renderer:draw() (620ms) and about 15% of reload_explorer.

Proposed fix

Call nvim_buf_set_extmark directly with the same ranges and the same priority (vim.hl.priorities.user). The highlights produced are identical. Happy to provide a PR for this ofc.

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 摘要。