reason-mode icon indicating copy to clipboard operation
reason-mode copied to clipboard

reason-mode-indent-line performance issue

Open shahinism opened this issue 6 years ago • 10 comments

Issue:

Issuing indent command, the editor will hang forever. The only option to continue is canceling the command (Ctrl-g).

Setup

  • Emacs: 25.3.1
  • My emacs configuration can be found here

Profile

Here is profiling result on both CPU and Memory: selection_029

update: The image includes more expanded tree, which shows maybe the issue is caused by the constant call of syntax-ppss function.

shahinism avatar Dec 14 '17 15:12 shahinism

To reproduce this problem just trigger indentation between || in following lines:

[%%bs.raw {|

|}]

It looks like Emacs enters an infinite loop when it hits this lines of code here.

shahinism avatar Dec 15 '17 08:12 shahinism

Thanks, I'll have a look soon. Do you wanna PR a failing test case?

anmonteiro avatar Dec 16 '17 14:12 anmonteiro

About PR on a failing test, I'm a newbie on emacs-lisp and don't know how to express an assertable unit for this scenario (Infinite loop).

shahinism avatar Dec 19 '17 05:12 shahinism

@shahinism there are some tests here https://github.com/reasonml-editor/reason-mode/blob/master/test/reason-test.el if you'd like to model yours after them

anmonteiro avatar Dec 19 '17 13:12 anmonteiro

Well, I've already tried it. The problem is I don't know how to timeout this test. And the current test suite will just hang in the loop and block all the process.

shahinism avatar Dec 19 '17 19:12 shahinism

I'm also experiencing this issue but with the jest testing syntax: describe("functionToTest", () => {...}) As soon as I enter the curly brackets the editor (spacemacs) hangs.

gunnigylfa avatar Jan 10 '18 16:01 gunnigylfa

I have the same issues. In the beginning I thought it is a problem with the file-naming and weird __tests__ path...

I found a funny quick fix though: As soon as you start your file with a simple declaration like let a = "", suddenly there are no hangups on indent anymore.

EDIT:

Or another way to prevent the freeze:

let _ = foo("hi", () => {
});

ryyppy avatar Jan 20 '18 14:01 ryyppy

I just encountered this bug. For me, I simply change indent-line-function to indent-relative and let refmt-before-save take care of indenting when I save a file.

@shahinism is absolutely right. The infinite loop is right there. The value current-level and (reason-paren-level) are both 0 are stay like that forever (the point is moved upward until it couldn't and then get stuck forever).

The reason @ryyppy 's workaround works is because of line https://github.com/reasonml-editor/reason-mode/blob/a9de59cced37b44db72ee248107021a660561d11/reason-indent.el#L175. In fact, any let, type, module, fun will do.

sorawee avatar Jul 25 '18 12:07 sorawee

@sorawee thanks for looking into this in depth. To be honest, the reason-mode-indent-line function is kind of a mess.

Do you see a path forward?

anmonteiro avatar Jul 25 '18 12:07 anmonteiro

I don't have time to investigate further. That's why I simply switch reason-mode-indent-line off.

sorawee avatar Jul 25 '18 13:07 sorawee