neomacs icon indicating copy to clipboard operation
neomacs copied to clipboard

[Bug]: extremely slow when loading a repo with huge commit history

Open definepi opened this issue 1 week ago • 12 comments

Bug summary

还是doom,只要加载一个可能是merge或分支较多的repo,再返回第一行,就能发现neomacs会卡住。GNU的在多按几次Enter时,最多只卡1~2秒,最后Load完core的所有历史后再evil-goto-line是即时不卡的。

是兄弟就多提bug ^_^

Steps to reproduce

  1. git clone https://github.com/doomemacs/core.git
  2. neomacs打开这个core仓库
  3. (magit-status),(magit-log-current),G(evil-goto-line 去到最后一行),Enter((push-button &optional POS USE-MOUSE-ACTION)),Enter,Enter,Enter,Enter(卡好几秒),gg (evil-goto-first-line) 卡好久,C-g也不行

Expected behavior

No response

Neomacs --version output

Neomacs 0.0.21
Git commit: 7b3fa9d698ba41fdbabccd9bd3e547a0afa7164a
Source date: 2026-11-22T03:37:02.000000000-05:00
Build: release-pgo for x86_64-unknown-linux-gnu with rustc 1.96.1
Standalone Rust binary for Neomacs (no C dependency)

Platform

Linux (Wayland)

Install source

Prebuilt release asset (downloaded from Releases)

Extra context

No response

definepi avatar Nov 23 '26 06:11 definepi

谢谢,又一个很有价值的报告!已经分配处理。这里有两个问题,我们会分开处理:

  1. 性能:大量提交历史的 magit-log buffer 里反复"显示更多历史",然后跳到开头(gg / M-<)非常慢。
    • 我们会先在不带 Doom 的环境(-Q + magit)里复现。
    • 每一步都和 GNU Emacs 31.1 计时对比,再做 profile 找出耗时的地方。
  2. C-g 打断不了:长时间的重绘或命令应该像 GNU 一样可以被 C-g 中断。这是兼容性 bug,会单独修,并加回归测试。

(另外:main 上目前还有一个 v0.0.21 之后引入的正则搜索性能退化,正在修复中。它不影响你用的 0.0.21,但我们测量时会注意把它排除。)


English summary. There are two separate problems, both assigned:

  1. Performance: the large magit-log buffer is slow on repeated "show more history" and then on the jump to the top. We'll reproduce it without Doom (-Q plus magit), time each step against GNU Emacs 31.1, and profile it.
  2. C-g doesn't interrupt the long operation: this is a GNU-compatibility bug and gets its own fix and regression test.

eval-exec avatar Nov 23 '26 06:11 eval-exec

进展:我们在 -Q(无 Doom)+ magit、终端界面下,用 doomemacs/core 仓库按你的步骤和 GNU Emacs 31.1 逐步计时对比了:

步骤 GNU(命令 / 重绘,秒) Neomacs(命令 / 重绘,秒) 行数
打开 log(256) 0.206 / 0.003 0.231 / 0.016 257
第 1–4 次 Enter 0.26–0.84 / ~0.003 0.24–0.69 / 0.007–0.024 513–4129
第 5 次 Enter 2.811 / 0.007 1.739 / 0.033 9448
回到第一行 0.000 / 0.002 0.031 / 0.007

在这个环境里,第 5 次 Enter 两边都慢(Neomacs 不比 GNU 慢),回到第一行也是瞬间完成,没有复现卡住。所以卡住应该来自你环境里 -Q 没有的部分:GUI(Wayland)重绘、Doom 的默认设置(例如行号 display-line-numbers、hl-line)或 evil 的 gg。我们接下来会在 GUI 下逐个加上这些再测。

如果方便,请帮忙确认两点:

  1. 卡住时,那个 buffer 里是否显示行号?用 M-x display-line-numbers-mode 关掉行号后,gg 还卡吗?
  2. 卡住之后,最终能恢复吗?大概要多久?

eval-exec avatar Nov 23 '26 12:11 eval-exec

进展更新:我们又在 GUI 下(Xvfb,窗口 200x50)按你的步骤计时,对照 GNU Emacs 31.1(通过 check-gnu-oracle.sh 校验的构建)。时间格式为“命令秒 / 重绘秒”:

步骤 GNU Neomacs
打开 log(256) 0.246 / 0.024 1.258 / 0.013
第 5 次 Enter(9448 行) 1.393 / 0.007 3.514 / 0.038
回到第一行(goto point-min) 0.000 / 0.003 0.026 / 0.005

我们也逐个加上了 Doom 常用的设置再测:

  • 行号(display-line-numbers,绝对行号);
  • hl-line;
  • evil 的 G / gg;
  • 一个带 :eval 的 mode-line。

结果:

  • 跳回第一行在所有组合下都低于 50 ms,没有复现“卡住”。
  • 但 Neomacs 的第 5 次 Enter 明显比 GNU 慢:-Q 下 3.5 秒对 1.4 秒,开行号时 5.2 秒对 1.3 秒。这一点我们会继续优化。

还没覆盖的部分:真实的 Wayland 合成器、完整的 Doom 配置,以及你使用的 v0.0.21 AppImage。

为了继续定位,请帮忙确认:

  1. 卡住时是哪一步(打开 log、按 Enter 展开,还是跳回第一行)?
  2. 卡住是几秒后恢复,还是一直不恢复?卡住期间如果按 C-g 有没有反应?

eval-exec avatar Nov 24 '26 04:11 eval-exec

更新:修复已合入 main(9cd707ae0f)。

根因:char-displayable-p(magit 在每个 section 的省略号上都会调用)走到 internal-char-font。Neomacs 每次调用都会重建整张 frame 的 face 表,包括 X 颜色查找,并且每次都重新构造字体对象。GNU 则直接使用已经 realize 好的 face 和它的字体。

修复:

  • 23935e7db8:internal-char-font 改用 redisplay 已有的 realized face 缓存,只在 face 改变时才重建。
  • d95ee6bccb:直接返回该 face 已打开的字体对象。和 GNU 一样,同一 face 下多次调用返回 eq 的对象。

计时:GUI(Xvfb),-Q,第 5 次 show-more Enter,9448 行:

版本 耗时
修复前 Neomacs 3.51 s
修复后 Neomacs 1.52 s
GNU Emacs 31.1 1.39 s

请用最新 main 再试一次,看看卡顿是否还在。如果在你的 Doom/Wayland 环境下仍然明显变慢,请贴一下 M-x emacs-version 和大概的步骤。

eval-exec avatar Nov 24 '26 10:11 eval-exec

我是在加载了doom配置(应该是10月份的)的情况下实测对比gnu和Neomacs的,没有任何定制的配置。 恰好doomemacs/core是个有很多历史的Repo,所以用它做演示。 最后的一下gg应该是一直卡住了,多次按Ctrl-g也没用。 需要的话我可以再复现一次。 哦,你有更新的话我从哪里下载Prebuilt的?

darkhandz avatar Nov 24 '26 11:11 darkhandz

谢谢!gg 一直卡住、多次按 C-g 也没反应,这是两个需要单独跟进的问题:

  1. gg 卡住:我们会用 doomemacs 仓库(历史很长)复现这一步。
  2. C-g 无法中断:GNU Emacs 在长时间操作中能被 C-g 打断,Neomacs 也应该如此。这是兼容性 bug,会单独修。

获取新版本:目前没有 nightly 预编译包。这个修复(以及上面两项)会进入下一个正式版 v0.0.22,Releases 页面会提供预编译包。如果想先试 main,可以从源码构建:

git clone https://github.com/eval-exec/neomacs && cd neomacs
nix develop --accept-flake-config   # 可选,推荐
cargo xtask fresh-build --release
./target/release/neomacs

另外,上面评论里的两个提交号是 rebase 之前的;在 main 上对应的是 8a2599186a 和 82ab1d8822。

如果你方便再复现一次,请告诉我们在 gg 之前的大致步骤(magit-log 的哪个视图、按了几次 Enter / show-more),以及卡住时 CPU 是否满载。这样能帮我们更快定位。

eval-exec avatar Nov 24 '26 14:11 eval-exec

还是这个版本,我用nw重现了一次

Neomacs 0.0.21
Git commit: 7b3fa9d698ba41fdbabccd9bd3e547a0afa7164a
Source date: 2026-11-22T03:37:02.000000000-05:00
Build: release-pgo for x86_64-unknown-linux-gnu with rustc 1.96.1
Standalone Rust binary for Neomacs (no C dependency)
HOME=/home/dark/Downloads/emacs-test-env/home RUST_LOG=info NEOMACS_LOG=info NEOMACS_LOG_FILE=/home/dark/Downloads/neomacs-debug_nw.log  /home/dark/Downloads/neomacs-0.0.21-x86_64-unknown-linux-gnu.AppImage -nw 

再次强调我是加载了10月份的doom默认配置的。 打开doomemacs的core代码, SPC g g (magit-status),l l(log current),G (evil-goto-line), Enter,Enter,Enter,Enter,Enter(大概1秒),Enter(大概3秒),Enter(大概4秒),按gg 没有到第一行,minibuffer出现g- (C-h for help)提示,按什么键都没有反应了,按C-g也没有用,等了一阵(可能有30秒了),恢复了,回到了第一行且出现Transient菜单等待我按键。

neomacs-debug_nw.zip

definepi avatar Nov 25 '26 03:11 definepi

Status update: the gg hang on large Magit logs is fixed on main (929cc58c49, now in 5f5a239737). Layout no longer fails to converge on buffers with many overlays, and that failure was what kept gg from returning.

The C-g changes are reviewed and queued for the next batch:

  • force_quit_count now follows GNU's quit rules.
  • A second C-g on the controlling TTY now gives GNU's emergency-escape prompts, including the orderly auto-save shutdown on Abort.

These will all ship in v0.0.22. If you can build from main, a retest of gg on your repository would help.

eval-exec avatar Nov 25 '26 05:11 eval-exec

Two separate causes here are fixed on main (cab08eb094):

  • the gg non-convergence: 929cc58c49
  • the second C-g being ignored on a controlling TTY: 4a00666371

A further improvement (bounded overlay-view ceiling when resolving forward scroll) is signed and queued for the next batch. Could you retest on magit-log against a large repository and tell us whether gg/G and C-g now behave? The issue is worth keeping open until you have had a chance to try it on the repo that originally showed the problem.

eval-exec avatar Nov 25 '26 21:11 eval-exec

我自己在Commit 9ca34ff 上编译测试了一下,gg卡住的问题解决了,C-g的问题由于没有出现gg卡住,我不好试它是不是解决了。

definepi avatar Nov 26 '26 11:11 definepi

测试结果收到,谢谢你在 9ca34ff 上自己编译验证 —— 这比我们跑任何 benchmark 都有说服力。

gg 卡住:已确认修复。 对应提交是 929cc58c49(gg non-convergence on large overlay buffers),在你最初复现的仓库上通过,这就是我们需要的证据。

C-g:无法再复现它的触发条件,这是好事而不是缺口。 第二个 C-g 失效只会在 gg 卡住时才会暴露(第一条 C-g 打断卡住的搜索,第二条必须还能继续生效)。既然 gg 不再卡住,这条路径就不会被走到,你没有办法测试它是正常的。我们保留 4a00666371 的自带单元测试作为覆盖;如果你日后在任何场景下发现需要连按两次 C-g 才有反应,请直接在这个 issue 里反馈,我们会立刻重开调查。

现在正在合并的最后一项相关改动是「forward scroll 解析时的 bounded overlay-view ceiling」(v10x/libval-607-stage1-coverage-storm,已在 gate 中)。等它落地后我们会关闭这个 issue,并在关闭评论里附上全部提交映射和 oracle 对比数据。如果关闭之后问题又出现,请直接重开,不要新建 issue。


Short English summary: the reporter independently compiled 9ca34ffd1c and confirmed the gg hang is fixed (929cc58c49). The second-C-g path can no longer be retested because its trigger (the hang) no longer occurs; it stays covered by its own unit rows. We will close this issue once the final related change lands, with the full commit mapping, and invite a reopen rather than a new issue.

eval-exec avatar Nov 26 '26 12:11 eval-exec

已在主分支上确认修复并关闭这个 issue。谢谢你花时间自己编译 9ca34ff 复现验证 —— 那是这个 issue 能关闭的直接依据。

修复提交(全部已核实位于 d9813b08af 的历史中)

直接修复 #829 的三个提交(Batch 77d,均可在 9ca34ffd1c 上验证):

提交 内容
c6c86ff0d0 前向滚动 / 跳到 buffer 顶部时不再做整个 buffer 的 overlay 扫描,改为按范围有界的 overlay 查询(就是 Magit log 里 gg 卡住的那条路径)
72ad3984e7 给有界 overlay 视图的跨度加上上限,并在范围视图复用时保留 CollectionReads 记账
17019047a1 折叠扫描的下界对称性,以及范围快照的可见性封闭

上述修复依赖的三个前置提交(更早落地,同样在主分支历史中):

提交 内容
cb8121c20b NEOMACS_LAYOUT_OVERLAY_SOURCE 默认切到 live,启用实时索引的 overlay 视图,不再为每次布局物化整个 buffer 的 overlay 快照
291eb8021d 按 overlay 缓存属性掩码,禁止在端点发布阶段做被观察的读取
0044c60835 让 overlay 索引冷边界的锁序回归测试变得确定

性能与兼容性证据

  • Magit log gg 工作负载:指令数从修复前约 20.2B 降到 5.79B(GNU Emacs 31.1 同一工作负载为 4.81B),降幅约 71%。注意:这是 N=1 单次测量,两条测量臂都使用 Live overlay source,只能作为方向性证据,不是统计结论。
  • GNU Emacs 31.1 oracle 兼容性:相关 oracle 行 14/14 通过。

后续仍在进行的工作

大 buffer 滚动/覆盖计算还有进一步优化在推进中(#607:Stage 1 已随本次一起上主分支,Stage 2A 正在评审、2B 在设计)。这些是进一步的性能改进,不影响本 issue 已经修复的 gg 卡死问题。

如果再次遇到:请重新打开这个 issue,或者新开一个并附上 neomacs-version、仓库规模(提交数 / 工作树状态)、复现步骤,以及 NEOMACS_LAYOUT_OVERLAY_SOURCE 的设置。带数字的报告(可以用 perf stat 或 time)对我们定位最有帮助。

再次感谢报告和验证。

eval-exec avatar Nov 26 '26 12:11 eval-exec