jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.36k stars 242 forks source link

Glossary links cause Emacs to freeze for several seconds on mouseover #1120

Open lrustand opened 1 month ago

lrustand commented 1 month ago

Any gls: link in my org documents causes Emacs to become fully unresponsive and freeze for several seconds when my mouse pointer accidentally hover over it. This is extremely annoying when I have a document where there are many glossary references, for example scrolling through the document becomes very cumbersome, since the mouse pointer will hit many links while scrollling, which causes the scrolling (and any other action I try to do) to freeze.

All other types of org-ref links work fine and do not cause this problem. It only happens for glossary links.

I have tried every possible way of disabling these pointless popups, but the freeze happens anyways.

lrustand commented 1 month ago

There seem to be two separate freezes. First it freezes for roughly one second before loading the tooltip, then it freezes for roughly one second before removing it also.

lrustand commented 1 month ago

And the freezes seem to be "queued up". So if I move my mouse pointer around and hover over several links in short succesion it queues up all the tooltips and will be unresponsive until it has shown all the tooltips that I have hovered over.

jkitchin commented 1 month ago

You can probably suppress the problem with (setq org-ref-activate-glossary-links nil). The freezing probably occurs from fontification which is scanning the org-buffer to see if it is valid. This code could use an overhaul, to address that, but I am not sure when I will have time to do that.

For future me: I should see if I can save a text-property once, and reuse that on subsequent fontification. The difficult is cache invalidation here, e.g. if you delete a char or add one, it should become invalid.

lrustand commented 1 month ago

Thanks, I tried that, but unfortunately it didn't help. It certainly had an effect on something since the links changed color from orange to purple, but I'm not sure it did what was intended. The glossary references still act like links when clicked, they are highlighted and show the tooltip when hovered, and the freezes are still in full effect.

Edit: Btw, all my glossary entries are actually acronyms made with \newacronym if this makes any difference.

jkitchin commented 1 month ago

I guess you might be able to suppress this for now by redefining these function:

(defun or-acronym-tooltip (_window _object position)
  "acronym")

(defun or-glossary-tooltip (_window _object position)
  "glossary")

Could you send me the file causing this issue? I can't reproduce the freezing here, which makes it hard to tell what to change.

Also, could you say a little more about your system? operating system, windows/mac, etc...

lrustand commented 1 month ago

Unfortunately I can't upload the actual file that I'm working on to the internet, so I will try to create a MWE that reproduces it, and will post that if I manage to isolate it.

Operating system is Guix, and Emacs is version 30.0.60

Edit: At least your new workaround worked perfectly. So now this is a non-problem for me personally, but I will try and see if I can reproduce it anyway just in case this is a bug that might affect other people as well.

lrustand commented 1 month ago

After a bit more testing it seems like the length of the freeze is dependent on the lenght of the document. When I made a minimal example with just one acronym and a reference to it, it works fine and responds instantly. However, if I just add a few thousand lines of random text to the same file it becomes very sluggish, but it becomes already noticeable after just a few hundred lines, especially if you hover over multiple different/the same link in a row. And the more text I add the more sluggish it becomes.

The following minimal example is enough to reproduce it if you append a few thousand lines of random build logs or whatever to the end of the file:

#+title: Test

#+LATEX_HEADER_EXTRA: \newacronym{ABC}{ABC}{A B C}

gls:ABC

Using this approach I get several seconds of delay until Emacs becomes responsive again.

To see the delay after hovering just try to click anywhere in the text to move the cursor and see that it takes a long while for the cursor to move, or try to execute any other keybinding.

If you don't get a noticable delay, try moving your mouse over the link and away quickly several times in a row or add more random text to the end of the file.

jkitchin commented 1 month ago

I made an attempt to speed things up above. let me know if it seems better, or if I added any new bugs.

lrustand commented 1 month ago

This seems to have worked very well, I'm not able to force a freeze even if I'm actively trying to cause as many hovers as possible. One side effect though is that the tooltip now says "nil: ." instead of the actual text.