agda / agda

Agda is a dependently typed programming language / interactive theorem prover.
https://wiki.portal.chalmers.se/agda/pmwiki.php
Other
2.41k stars 339 forks source link

agda-mode syntax highlighting slows down Emacs signficantly #7069

Open noughtmare opened 5 months ago

noughtmare commented 5 months ago

Summary

I have noticed that the highlighting of the agda-mode plugin makes my Emacs considerably less responsive. Many operations such as scrolling and inputting text incur a noticeable delay.

Reproducer

For example take the file that is generated by this Haskell script:

template n = 
  [ "foo" ++ show n ++ " : forall {X1 X2 X3 X4 : Set} -> (X1 -> X2 -> X3 -> X4) -> X1 -> X2 -> X3 -> X4"
  , "foo" ++ show n ++ " f x y z = f x y z"
  , ""
  ]

main = writeFile "test.agda" (unlines (concatMap template [1..100 :: Int]))

If I start a clean emacs with emacs -Q and then load agda-mode using this command:

(load-file (let ((coding-system-for-read 'utf-8))
                (shell-command-to-string "agda-mode locate")))

Then open test.agda and check it with C-c C-l. In the resulting highlighted file, scrolling with my mouse wheel or by dragging the scrollbar with my mouse has a very noticeable lag (it also seems to depend on the window size, at very small sizes it is not that noticeable). The lag disappears if I clear the highlighting with M-x agda2-highlight-clear.

I have also tried the same experiment with a highlighted C++ file which I generated by copying and pasting this example 5 times. That seems to have a similar amount of highlighting, but that does not suffer from the performance hit. So this doesn't seem to be inherent to Emacs highlighting.

Version info

I can also reproduce this on a different machine with NixOS unstable (but it does seem less noticeable):

UlfNorell commented 5 months ago

I doesn't reproduce for me. I'm on Sonoma 14.2 (M1), and GNU Emacs 28.1 (don't know how to get the fancy stuff in parentheses). Scrolling has no detectable lag even full screen on a 4k display.

noughtmare commented 5 months ago

don't know how to get the fancy stuff in parentheses

I'm using M-x emacs-version

UlfNorell commented 5 months ago

Fancy stuff: GNU Emacs 28.1 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559)) of 2022-05-11

dsheets commented 4 months ago

I have the same issue. I have tried to use emacs's profiling support to track it down to no avail.

dsheets commented 4 months ago

After downgrading to GNU Emacs 28.2 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559)) of 2023-02-22 the performance has significantly improved.

The issue with the 29 series seems to be internal to the Emacs process itself and not the agda subprocess.

I run with emacsclient and the default Emacs for OS X builds I use were pointing bin and libexec to the x86_64-10_11 variant and with a 'fat' Emacs binary. I did switch the symlinks to the arm64-11 variant and I used lipo on the Emacs binary to retain only the arm64 executable but these actions seemed to have no noticeable impact on the poor performance.

I think my next task in this investigation would be to use profiling tools external to Emacs and perform a comparative analysis of 28.2 and 29.x to determine what seems to have regressed the UX.

noughtmare commented 4 months ago

It might be slightly faster, but the lag is still very noticeable for me on: GNU Emacs 28.2 (build 2, x86_64-apple-darwin23.3.0, NS appkit-2487.40 Version 14.3 (Build 23D56)) of 2024-02-22 (that's from brew install emacs-plus@28)

dsheets commented 4 months ago

I note that some of the components are still much newer. Could you try https://emacsformacosx.com/emacs-builds/Emacs-28.2-universal.dmg? It should be relatively easy to install/uninstall to/from /Applications and could help give us a differential. You might need to reinstall melpa packages or recompile agda-mode elisp or something, of course.

dsheets commented 4 months ago

I did not have these performance issues with:

andreasabel commented 4 months ago

I also find scrolling in a highlighted Agda file very slow: GNU Emacs 29.1 (build 2, x86_64-apple-darwin21.6.0, NS appkit-2113.60 Version 12.6.7 (Build 21G651)) of 2023-09-04 macOS 12.7.1 (21G920) Monterey Kernel Version: Darwin 21.6.0

noughtmare commented 4 months ago

Could you try https://emacsformacosx.com/emacs-builds/Emacs-28.2-universal.dmg?

Still noticeable lag. It may be slightly faster but it's hard to tell.

It gives me this version: GNU Emacs 28.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95)) of 2023-02-22