Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lrustand opened this issue Jul 26, 2024 · 9 comments
Open

Comments

@lrustand
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

jkitchin commented Jul 26, 2024

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
Copy link
Author

lrustand commented Jul 31, 2024

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
Copy link
Owner

jkitchin commented Aug 1, 2024

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
Copy link
Author

lrustand commented Aug 1, 2024

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
Copy link
Author

lrustand commented Aug 1, 2024

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 pushed a commit that referenced this issue Aug 2, 2024
I have tried to make it only parse the document once, and then use a cache on
subsequent lookups. I found an error in the cache where it wasn't using the
right test for equal that is fixed now. I also store data on text properties
now, so it should be much faster to compute faces and tooltips.

Some things are not quite as good as I want, like following links is not as
precise as I would like, and may still need some fine tuning.

hopefully this is more performant in large files.
@jkitchin
Copy link
Owner

jkitchin commented Aug 2, 2024

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

@lrustand
Copy link
Author

lrustand commented Aug 2, 2024

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.

jkitchin pushed a commit that referenced this issue Aug 2, 2024
1. tooltip error when point is in another buffer
2. tooltips are not nil when using an acronym with  glossary link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants