flycheck / flycheck-haskell

Improved Haskell support for Flycheck
GNU General Public License v3.0
67 stars 25 forks source link

flycheck-haskell is very slow when stack.yaml is not pressent #98

Open turboMaCk opened 5 years ago

turboMaCk commented 5 years ago

Hello :wave:

I have huge performance issues with using flycheck-haskell on any project that doesn't use stack as a build tool. Even basic text editing is incredibly slow while working on those files. The workaround is to $ touch stack.yaml which fixes the issue (no matter that file is empty). Another possible workaround is to uninstall stack completely from the system. It seems to me that something has to be recursively looking for nearest stack.yaml file while blocking the ui.

Tested on NixOS using GNU Emacs 25.3.1 and GNU Emacs 26.1 with the latest version of flycheck-haskell.

sergv commented 5 years ago

@turboMaCk Hi, thanks for the report and conducted investigation. However, I cannot reproduce the slowdown - I've created a simple cabal project with a .hs file and a .cabal file and tried editing the .hs file. I notice no significant slowdown compared to my usual editing.

To help the investigation, can you please conduct some emacs profiling to show what's being slow for you? For example:

turboMaCk commented 5 years ago

Well I just found some time and wanted to try it again (previously I solved it by uninstalling stack). I can no longer reprouce it but before it seemed like unavoidable issue no matter what I tried. Since then I did both update system and emacs packages and did other changes so likely something of that unknowingly to me solved the issue.

I'm using nixos which is quite different compare to most of linux distributions, there might even been some fix for some stack issue on nixos.

Since this is irreproducible now I'm closing the issue.

turboMaCk commented 5 years ago

I still have a problems with this from time to time. This is a profile report. It might be something specific to my config. I would apprichiate any advice but if you think this is not related to flycheck-haskell feel free to just close this issue.

- command-execute                                                 264  45%
 - call-interactively                                             264  45%
  - apply                                                         264  45%
   - call-interactively@ido-cr+-record-current-command                264  45%
    - apply                                                       264  45%
     - #<subr call-interactively>                                 264  45%
      - byte-code                                                 259  45%
       - helm-M-x-read-extended-command                           259  45%
        - helm-comp-read                                          259  45%
         - helm                                                   258  44%
          - apply                                                 258  44%
           - helm                                                 258  44%
            - apply                                               258  44%
             - helm-internal                                      258  44%
              - helm-read-pattern-maybe                           220  38%
               - read-from-minibuffer                             199  34%
                - timer-event-handler                             136  23%
                 - apply                                          135  23%
                  + #<compiled 0x1338889>                         129  22%
                  - auto-revert-buffers                             2   0%
                     apply                                          2   0%
                - command-execute                                  12   2%
                 - call-interactively                              12   2%
                  - apply                                          12   2%
                   - call-interactively@ido-cr+-record-current-command                 12   2%
                    - apply                                        12   2%
                     + #<subr call-interactively>                  12   2%
                + redisplay_internal (C function)                   5   0%
                - flycheck-handle-signal                            2   0%
                 - seq-do                                           2   0%
                  - mapc                                            2   0%
                   - flycheck-safe-delete                           2   0%
                    + delete-file                                   2   0%
                - linum-update-current                              2   0%
                 - linum-update                                     2   0%
                  - mapc                                            2   0%
                   - linum-update-window                            2   0%
                      linum--face-width                             1   0%
                - minibuffer-inactive-mode                          1   0%
                 - run-mode-hooks                                   1   0%
                  - run-hooks                                       1   0%
                   - global-undo-tree-mode-enable-in-buffers                  1   0%
                      turn-on-undo-tree-mode                        1   0%
                - global-hl-line-maybe-unhighlight                  1   0%
                 - mapc                                             1   0%
                    #<compiled 0xd94291>                            1   0%
               - helm-update                                       13   2%
                - helm--collect-matches                             5   0%
                 - helm-compute-matches                             5   0%
                  - helm-process-filtered-candidate-transformer                  5   0%
                   - helm-apply-functions-from-source                  5   0%
                    - apply                                         5   0%
                     - helm-M-x-transformer                         4   0%
                      - helm-M-x-transformer-1                      4   0%
                       - sort                                       3   0%
                        - helm-generic-sort-fn                      3   0%
                           #<compiled 0x127a809>                    2   0%
                     - helm-M-x-transformer-hist                    1   0%
                        helm-M-x-transformer-1                      1   0%
                + #<compiled 0x20db821>                             4   0%
                - helm--update-move-first-line                      3   0%
                 - helm-move-selection-common                       3   0%
                    helm-display-mode-line                          3   0%
                - helm-render-source                                1   0%
                   helm-insert-match                                1   0%
               + helm-get-candidate-number                          1   0%
              + helm-initialize                                    24   4%
              + #<compiled 0x133590d>                               8   1%
              + helm-display-buffer                                 6   1%
         - helm-make-source                                         1   0%
          + helm--setup-source                                      1   0%
      - funcall-interactively                                       5   0%
       + evil-normal-state                                          3   0%
       + evil-previous-visual-line                                  2   0%
- ...                                                             179  31%
   Automatic GC                                                   178  30%
 - helm-major-mode                                                  1   0%
  - run-mode-hooks                                                  1   0%
   - run-hooks                                                      1   0%
    - evil-mode-enable-in-buffers                                   1   0%
     - evil-initialize                                              1   0%
      + evil-local-mode                                             1   0%
- timer-event-handler                                              66  11%
 - apply                                                           66  11%
  - ac-update-greedy                                               55   9%
   - ac-update                                                     55   9%
    + ac-menu-create                                               50   8%
    + ac-candidates                                                 4   0%
    + ac-menu-delete                                                1   0%
  + auto-revert-buffers                                             5   0%
- linum-update-current                                             21   3%
 + linum-update                                                    21   3%
+ ac-handle-post-command                                           21   3%
+ flycheck-handle-signal                                           11   1%
+ flycheck-perform-deferred-syntax-check                            6   1%
+ redisplay_internal (C function)                                   4   0%
  evil-repeat-pre-hook                                              1   0%
+ winner-save-old-configurations                                    1   0%
  evil-repeat-post-hook                                             1   0%
sergv commented 5 years ago

@turboMaCk Thanks for coming back. One question I didn't manage to ask in this thread yet but which strikes me as a crucial one - do you observe stack executable running in the process explorer while you experience the slowness?

Unfortunately, the profiler report doesn't point no anything obvious - there's 30% spent on GC (probably flycheck wasn't directly involved) and 45% spent on a command invoked via M-x:

  + #<compiled 0x1338889>                         129  22%

Alas, report doesn't show what was actually invoked - there's ssome compiled lambda AFAIK and it's not clear, even if it was a flycheck-related function, what it was.

That being said, I think I'm going to go ahead and add a customization option to disable checking for stack altogether - if you don't want flycheck-haskell to do anything with stack then you'll be able to disable it completely. Would that be OK with you?

turboMaCk commented 5 years ago

To be honest looking at that trace I also start to think it's not realy flycheck-haskell related. I have no idea what it can be but perhaps if I find a time and try to reduce my config to some minimal reproducible example it would become more obvious.

If you want to add that option I definitely have no objections but it really depends on your judgement and not mine. if you feel like it has no other use than to solve this issue I would consider just closing this until I'm able to show how it is related and that such change can indeed mitigate the issue. My (design) guts tell me there is no reason to introduce and API which might be useful. The only thing I don't understand is why I don't observe this issue when I turn flycheck off.

mx-psi commented 4 years ago

I am having a similar issue. I am using Manjaro with GNU Emacs 26.3 (as a daemon). The profiling report is similar to the one that @turboMaCk gets (it doesn't point to anything obvious) and I can confirm that the stack executable is running while I experience the slowness.

Even if I uninstall the flycheck-haskell package and I just use flycheck I still have the slowness (only if the selected checker is haskell-stack-ghc).

turboMaCk commented 4 years ago

btw I'm also running Emacs as a daemon myself even though I don't see how it can be related.

turboMaCk commented 4 years ago

Have you found any solution @mx-psi ? I've solved it by uninstalling stack from my system last year but now I need to have stack installed because of work and this starts driving me mad when ever I work on project that doesn't use stack.

mx-psi commented 4 years ago

No, @turboMaCk, I did not manage to make any progress unfortunately :(

bqv commented 4 years ago

Seeing this too