syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.56k stars 4.9k forks source link

Slow opening of tex files #16372

Closed tigerjack closed 2 months ago

tigerjack commented 2 months ago

Description :octocat:

Opening any tex files takes seconds.

Reproduction guide :beetle:

To debug the issue

Observed behaviour: :eyes: :broken_heart: Opening any tex files takes seconds.

Expected behaviour: :heart: :smile: Opening any tex files takes way less.

System Info :computer:

Backtrace :paw_prints:

Debugger entered--Lisp error: (quit)
  require(evil-embrace nil t)
  evil-tex-mode()
  run-hooks(change-major-mode-after-body-hook text-mode-hook TeX-mode-hook LaTeX-mode-hook)
  apply(run-hooks (change-major-mode-after-body-hook text-mode-hook TeX-mode-hook LaTeX-mode-hook))
  run-mode-hooks(LaTeX-mode-hook)
  LaTeX-mode()
  set-auto-mode-0(latex-mode t)
  #f(compiled-function (var val) "Set local variable VAR with value VAL.\nIf VAR is `mode', call `VAL-mode' as a function unless it's\nalready the major mode." #<bytecode -0xc0cd9b4aaa588c1>)(mode LaTeX)
  apply(#f(compiled-function (var val) "Set local variable VAR with value VAL.\nIf VAR is `mode', call `VAL-mode' as a function unless it's\nalready the major mode." #<bytecode -0xc0cd9b4aaa588c1>) (mode LaTeX))
  hack-one-local-variable(mode LaTeX)
  hack-local-variables-apply()
  hack-local-variables(no-mode)
  run-mode-hooks(LaTeX-mode-hook)
  LaTeX-mode()
  set-auto-mode-0(latex-mode t)
  #f(compiled-function (var val) "Set local variable VAR with value VAL.\nIf VAR is `mode', call `VAL-mode' as a function unless it's\nalready the major mode." #<bytecode -0xc0cd9b4aaa588c1>)(mode LaTeX)
  apply(#f(compiled-function (var val) "Set local variable VAR with value VAL.\nIf VAR is `mode', call `VAL-mode' as a function unless it's\nalready the major mode." #<bytecode -0xc0cd9b4aaa588c1>) (mode LaTeX))
  hack-one-local-variable(mode LaTeX)
  hack-local-variables-apply()
  hack-local-variables(no-mode)
arifer612 commented 2 months ago

It might be helpful to run a profiler to check what's going on under the hood. My LaTeX files are humongous an even despite using LSP as the backend, it takes about a second (two tops) to load them all up.

tigerjack commented 2 months ago

@arifer612

Here is the CPU profiling, which shows a 70% of CPU time spent on evil-tex-mode cpu_profile.txt

arifer612 commented 2 months ago

Yep, 70% just for evil-tex-mode is quite significant. Unfortunately, I am not able to reproduce this issue with my setup, nor on a fresh setup with the most basic configurations. It might just be an unexpected issue or perhaps something amongst your currently installed packages are interfering with it. I would suggest upgrading all your packages first to see if there's improvement, and if there isn't then to delete the contents of ~/emacs.d/elpa/29.3 to force Emacs to re-download all the packages again.

tigerjack commented 2 months ago

@arifer612 thanks for your help. After further investigation, I discovered that the issue was due to the following (now commented) line in .dir-locals.el, probably firing a recursive activation of function calls.

((latex-mode
  ;; (mode . latex )
))

I don't why it got there first of all, or if it was used before the recent auctex upgrade.

arifer612 commented 2 months ago

You're welcome! On another note, that's quite a nasty recursive hell you ended up in :rofl:, good thing you caught that. Hope your TeX experience on Emacs/Spacemacs goes smooth from now on!

tigerjack commented 2 months ago

You're welcome! On another note, that's quite a nasty recursive hell you ended up in šŸ¤£, good thing you caught that. Hope your TeX experience on Emacs/Spacemacs goes smooth from now on!

It's incredible how fast a file is opening now XD for the last month or so, I got used to incredible amount of delays!