Khady / merlin-eldoc

Type and doc on hover for OCaml and Reason in emacs
GNU General Public License v3.0
43 stars 3 forks source link

Performance degraded horribly after introduction of highlighting of other occurrences of current value #24

Closed loxs closed 2 years ago

loxs commented 6 years ago

The package is borderline unusable for me right now on a MacBook Pro late 2013. The machine is a bit on the older side, but I had no problems using it for normal work till now.

The problem is that it probably tries to activate highlighting too soon while typing.

Could we either have an option to switch this highlighting off or maybe display it after a longer period of waiting?

loxs commented 6 years ago

I discovered (consulted the README) that indeed, there is an option to switch off the highlighting and I can confirm that when done, performance is back to normal.

Khady commented 6 years ago

I'm curious to know on what kind of file the performances get horrible. This is only one more call to merlin and a few overlays. It is a on very big file in big project, or it appears on small examples too?

There is no control over the period of waiting in this package, this is handled by eldoc. And I don't feel like adding a different waiting method for highlighting only.

All the features of merlin-eldoc can be disabled. You can see the list of options with M-x merlin-eldoc-customize.

It is probably possible to make the calls to merlin asynchronous, which would fix lags making this plugin uncomfortable to use because it's blocking other actions. But it would also make it useless when there is some lag. So I'm not sure it worth it.

loxs commented 6 years ago

My project is currently around 850 LoC dispersed in several files and it happens on all of them. Sometimes it's so slow that I type a whole word of more or around 10 chars, where it hangs during all that time and then the whole word appears at once.

It seems to hang if I wait around exactly 0.5 seconds so highlighting "starts" to appear (I have no idea if it's an animation)... and if I continue to write right then, it seems to trigger some pathological loop where it probably tries to highlight on every key press where it fails and tries again etc...

Khady commented 6 years ago

After 0.5s of idling the merlin-eldoc function is called by eldoc. If merlin-eldoc is doing something slow and blocking, you won't be able to type. But there is no action which is triggered after every keystroke.

I need to learn how to measure performances in emacs.

loxs commented 6 years ago

OK, this started to become unbearable even without using occurences. So I started digging further. I had a look into this two issues:

https://github.com/ocaml/merlin/issues/694 https://github.com/syl20bnr/spacemacs/issues/4207

I tried setting (setq shell-file-name "/bin/sh") and (setq projectile-enable-caching t) and both made a huge difference in a positive way. I enabled back occurences and it looks good so far. Still feeling a bit slower than when editing Erlang files with flycheck, but now I certainly prefer to have all the OCaml goodies switched on.

And while the first workaround is obvious as probably my OS/merlin were slow in the first place, I can't explain why merlin wasn't as slow on its own as it was while using merlin-eldoc on top.

So questions:

Does merlin-eldoc call merlin several times? Once for completion, once for docs, once for occurences? Is it possible that two consecutive calls get overlapped, which triggers a pathologic cycle if the first one (maybe for completion) is slow?

Does merlin-eldoc call projectile somehow directly or via its dependencies?

Khady commented 6 years ago

Thanks for the investigations.

So questions: Does merlin-eldoc call merlin several times? Once for completion, once for docs, once for occurences?

Yes, there is one call per feature. So if there is some delay, it will be very noticeable.

Does merlin-eldoc call projectile somehow directly or via its dependencies?

Not that I am aware.

I could try to make the calls the merlin async so that they can run in parallel and don't make the whole thing very slow. But I don't have much time to dedicate to this task, it will have to wait.

Wilfred commented 6 years ago

If you use M-x toggle-debug-on-quit, you can see a stacktrace when you press C-g. This is a great way of finding out what code is running when Emacs hangs.

loxs commented 6 years ago

It no more hangs with the above fixes. I would consider them a definitive solution to the problem (after a month of everyday usage and no problems)

bbatsov commented 2 years ago

4 years later probably we can close this ticket. :-)