joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.25k stars 202 forks source link

Request: Asynchronous completion backend #61

Closed jojojames closed 6 years ago

jojojames commented 6 years ago

Hi, thanks for the package!

Working with completion-at-point/company-capf, it seems like completions are being done synchronously. Playing around with Emacs' codebase (window.c) and cquery, it seems there is slight lag/stutter when typing.

I gave a shot here but it seems too slow (typing latency is faster but completions take a while to return?) to be useable.

(setq-local company-backends '(company-eglot))
(setq-local company-idle-delay .01)

(defun company-eglot (command &optional arg &rest ignored)
  ""
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-eglot))
    (prefix
     (not (company-in-string-or-comment))
     (or (company-grab-symbol-cons "\\.\\|->\\|::\\|/" 2)
         'stop)
     ;; `company' won't continue completion with this.
     ;; (when eglot--managed-mode
     ;;   (symbol-at-point))
     )
    (candidates
     (let ((current-buffer (current-buffer)))
       (cons
        :async
        (lambda (cb)
          (let ((server (eglot--current-server-or-lose)))
            (jsonrpc-async-request
             server
             :textDocument/completion
             (eglot--TextDocumentPositionParams)
             :deferred :textDocument/completion
             :success-fn
             (lambda (resp)
               (let* ((items (if (vectorp resp) resp (plist-get resp :items)))
                      (result (mapcar
                               (jsonrpc-lambda (&rest all &key label insertText &allow-other-keys)
                                 (let ((insert (or insertText label)))
                                   (add-text-properties 0 1 all insert)
                                   (put-text-property 0 1 'eglot--lsp-completion all insert)
                                   insert))
                               items)))
                 (with-current-buffer current-buffer
                   (funcall cb result))))
             :error-fn (lambda (error))))))))))
joaotavora commented 6 years ago

too slow (completions take a while to return?) to be useable.

Well, there's only so much we can do on eglot's side to "speed up" completions. We can't really speed them up, only keep the interface as responsible as possible while we frantically make requests and hope the responses arrive in time.

In that sense, even with company-capf (my preferred method of working with company since it works also without company, and thus with any future completion frontend) you can do it like this:

  1. Make a synchronous request that is cancelled as soon as the user types something. You can use while-no-input for that.
  2. If the request isn't cancelled then return whatever the return value is.
  3. If the request is cancelled return nil. The underlying request is still going to the server and the server will still respond, but that response is dirty so it is discarded.

This may or not be what your example is doing (I didn't fully understand it), but is the only way. I have tested this approach successfully in a common Lisp IDE called SLY. See its sly-eval function with is similar to jsonrpc-request.

In short, this is more than probably more correctly implemented in jsonrpc.el, by adding a cancel-on-input and cancel-on-input-retval parameters to jsonrpc-request and then using those parameters from eglot-completion-at-point.

joaotavora commented 6 years ago

Hi @jojojames

Can you try the commit I pushed to a temporary branch and tell me if it improves things for you? There are two things that I hope you could comment on:

  1. In your original report you mention typing latency could be faster, so please comment on that. It should be much faster, even if the company popup disappears momentarily when you are typing quickly.

  2. There's also something you don't mention in your original report, but which might have been hurt by this change: when backspacing some characters after some completion, the experience might now be slower since results aren't cached anymore. Please tell me if you see any slowdown/bother here.

Thanks in advance.

João

jojojames commented 6 years ago

In your original report you mention typing latency could be faster, so please comment on that. It should be much faster, even if the company popup disappears momentarily when you are typing quickly.

Yes. Much faster than before. I think it improves on both cold/warm completions (I guess when the completions aren't cached yet). It's much more noticeable on the cold/non-cached completions where the version on master branch of eglot pauses for half a second before continuing.

I think flymake-mode stalls the completion a little too. I did a quick eyeball-test disabling/enabling flymake-mode and it seems more smooth without flymake-mode on. The stall seems to happen as it shows the error/warning indicators in the fringe. I don't have any special flymake settings but could get your more info if that would help.

There's also something you don't mention in your original report, but which might have been hurt by this change: when backspacing some characters after some completion, the experience might now be slower since results aren't cached anymore. Please tell me if you see any slowdown/bother here.

Nothing that bothers me here.

joaotavora commented 6 years ago

Much faster than before.

OK, good. Can you tell me which server you are using?

I think flymake-mode stalls the completion a little too. I did a quick eyeball-test

Flymake-mode isn't really connected to completions. More importantly flymake only kicks in when you have stopped typing after a little while.

Indeed, the processing after receiving a lot of diagnostics is non-trivial, so that may explain the delay you see. However I need to see more than an eyeball test. Can you describe or show a controlled experiment? I need

Alternatively, you can use the profiler

M-x profiler start
;; do some things that you think are laggy or slow
M-x profiler-report
C-u RET ;; to expand the entries fully
copy the entries and post in this issue
terlar commented 6 years ago

I tried out this branch also (if I didn't mess up).

I have a big monorepo (unfortunately I can't share) which I tried to run a simple completion, first completion takes about 15 seconds. Next one takes between 1-2 seconds. I will see if I can find something smaller with similar issue.

This is the profile output if it helps:

- flyspell-post-command-hook                              130,113,322  71%
 - flyspell-check-word-p                                  130,088,874  71%
  - sit-for                                               130,045,874  71%
   - read-event                                           129,371,756  71%
    - timer-event-handler                                 129,298,834  71%
     - apply                                              129,298,834  71%
      - company-idle-begin                                129,095,256  71%
       - company-auto-begin                               129,088,072  71%
        - company--perform                                129,088,072  71%
         - company--begin-new                             129,088,072  71%
          - company-calculate-candidates                  128,769,296  70%
           - company--fetch-candidates                    128,769,072  70%
            - company-call-backend-raw                    128,769,072  70%
             - apply                                      128,769,072  70%
              - company--multi-backend-adapter            128,769,072  70%
               - company--multi-backend-adapter-candidates   128,769,072  70%
                - company-capf                            128,763,728  70%
                 - completion-all-completions             128,763,728  70%
                  - completion--nth-completion            128,763,728  70%
                   - completion--some                     128,763,728  70%
                    - #<compiled 0x404a8bbd>              128,763,728  70%
                     - completion-basic-all-completions   128,762,704  70%
                      - completion-pcm--all-completions   128,760,672  70%
                       - all-completions                  128,760,672  70%
                        - #<compiled 0x404a8b69>          128,760,672  70%
                         - #<compiled 0x404a8b41>         128,760,672  70%
                          - #<compiled 0x404a8b1d>        128,760,672  70%
                           - jsonrpc-request              127,773,988  70%
                            - apply                       127,773,988  70%
                             - #<compiled 0x41db6fc9>     115,102,964  63%
                              - accept-process-output     104,408,900  57%
                               - jsonrpc--process-filter    91,629,483  50%
                                - jsonrpc-connection-receive    87,612,999  48%
                                 - jsonrpc--log-event      87,590,307  48%
                                  - pp-to-string           46,625,545  25%
                                   - pp-buffer             27,445,239  15%
                                    - indent-sexp          26,748,251  14%
                                     - lisp-indent-calc-next     2,836,780   1%
                                        calculate-lisp-indent       792,103   0%
                                        type-of                 1,640   0%
                                     - indent-line-to       2,215,152   1%
                                        back-to-indentation     2,215,152   1%
                                       lisp-indent-initial-state         8,272   0%
                                      down-list               648,412   0%
                                   - prin1                    514,484   0%
                                      ns-unselect-line          4,874   0%
                                     generate-new-buffer       513,499   0%
                                   - #<compiled 0x405144c1>         8,272   0%
                                    - kill-buffer               8,272   0%
                                       tramp-flush-file-function         8,272   0%
                                   jsonrpc--call-deferred        12,408   0%
                                - jsonrpc--json-read        1,039,177   0%
                                 - json-read                1,039,177   0%
                                  - json-read-object        1,039,177   0%
                                   - json-read                981,469   0%
                                    - json-read-object        969,089   0%
                                     - json-read              508,418   0%
                                        json-read-array        68,760   0%
                                        json-read-number        22,208   0%
                                        json-read-keyword         9,294   0%
                                       json-add-to-object         3,287   0%
                                  generate-new-buffer         473,915   0%
                                - #<compiled 0x44890029>        58,710   0%
                                   symbol-overlay-refresh         3,280   0%
                                - #<compiled 0x40516491>        40,476   0%
                                 - kill-buffer                 29,916   0%
                                    tramp-flush-file-function        20,680   0%
                                  - posframe-auto-delete         9,236   0%
                                     posframe-delete-frame         9,236   0%
                               - timer-event-handler        7,399,235   4%
                                - apply                     7,399,235   4%
                                 - savehist-autosave        7,399,235   4%
                                  - savehist-save           7,294,682   4%
                                   - savehist-printable        72,642   0%
                                      generate-new-buffer         3,183   0%
                                     generate-new-buffer         1,061   0%
                              - jsonrpc--async-request-1       347,840   0%
                               - jsonrpc-connection-send       343,480   0%
                                - apply                       343,480   0%
                                 - #<compiled 0x41dba225>       343,480   0%
                                  - jsonrpc--json-encode       257,368   0%
                                   - json-encode              257,368   0%
                                    - json-encode-list        257,368   0%
                                     - json-encode-plist       249,180   0%
                                      - json-encode           188,008   0%
                                       - json-encode-list       178,008   0%
                                        - json-encode-plist       161,632   0%
                                         - json-encode        129,072   0%
                                          - json-encode-list       129,072   0%
                                           - json-encode-plist       129,072   0%
                                            - json-encode-key        92,884   0%
                                             - json-read-from-string        89,732   0%
                                                generate-new-buffer        67,904   0%
                                              - #<compiled 0x404a8c99>        13,640   0%
                                               - kill-buffer         4,136   0%
                                                  tramp-flush-file-function         4,136   0%
                                                json-read         8,188   0%
                                             - json-encode         2,096   0%
                                              - json-encode-string         2,096   0%
                                                 apply          2,096   0%
                                            - json-encode        28,000   0%
                                               json-encode-number        28,000   0%
                                              json-join         8,188   0%
                                         - json-encode-key        24,372   0%
                                          - json-read-from-string        24,372   0%
                                             generate-new-buffer        23,316   0%
                                             #<compiled 0x43e66169>         1,056   0%
                                           json-join            8,188   0%
                                         json-encode-number        10,000   0%
                                      - json-encode-key        61,172   0%
                                       - json-read-from-string        54,836   0%
                                          generate-new-buffer        42,440   0%
                                          json-read             9,236   0%
                                        - #<compiled 0x446c8ea5>         3,160   0%
                                         - kill-buffer          1,048   0%
                                          - posframe-auto-delete         1,048   0%
                                             posframe-delete-frame         1,048   0%
                                  - jsonrpc--log-event         80,126   0%
                                   - pp-to-string              62,938   0%
                                    - pp-buffer                20,020   0%
                                     - indent-sexp             19,796   0%
                                      - lisp-indent-calc-next        11,348   0%
                                         calculate-lisp-indent         9,236   0%
                                      generate-new-buffer         9,549   0%
                               - jsonrpc-connection-ready-p         4,360   0%
                                - cl--generic-cache-miss         4,360   0%
                                 - cl--generic-make-next-function         4,360   0%
                                  - cl--generic-build-combined-method         4,136   0%
                                   - cl-generic-combine-methods         4,136   0%
                                    - cl--generic-standard-method-combination         4,136   0%
                                       cl-generic-call-method         4,136   0%
                             - #<compiled 0x41dc1135>      12,671,024   6%
                              - eglot--signal-textDocument/didChange    12,671,024   6%
                               - jsonrpc-notify            12,599,964   6%
                                - jsonrpc-connection-send    12,599,964   6%
                                 - apply                   12,599,964   6%
                                  - #<compiled 0x41dba225>    12,599,964   6%
                                   - jsonrpc--log-event    12,476,794   6%
                                    - pp-to-string            138,268   0%
                                       generate-new-buffer         9,549   0%
                                     - pp-buffer                7,616   0%
                                        indent-sexp             6,336   0%
                                   - jsonrpc--json-encode        41,288   0%
                                    - json-encode              41,288   0%
                                       json-encode-list        41,288   0%
                               - eglot--VersionedTextDocumentIdentifier        53,516   0%
                                - eglot--TextDocumentIdentifier        53,516   0%
                                 - eglot--path-to-uri          53,516   0%
                                  - file-truename              29,804   0%
                                   - file-truename             28,756   0%
                                    - file-truename             4,192   0%
                                     - file-truename            4,192   0%
                                      - file-truename           4,192   0%
                                       - file-truename          2,096   0%
                                        - file-truename         2,096   0%
                                         - file-truename         1,048   0%
                                            file-truename         1,048   0%
                                  - url-hexify-string          23,712   0%
                                   - mapconcat                 23,712   0%
                                      #<compiled 0x446c7f79>        23,712   0%
                           - mapcar                           869,304   0%
                            - #<compiled 0x41dc2dd1>          869,304   0%
                             - apply                          869,304   0%
                              - #<compiled 0x41dc2dc5>        869,304   0%
                                 put-text-property              1,640   0%
                           - eglot--TextDocumentPositionParams       117,380   0%
                            - eglot--TextDocumentIdentifier       113,156   0%
                             - eglot--path-to-uri             104,968   0%
                              - file-truename                  92,588   0%
                               - file-truename                 18,472   0%
                                - file-truename                18,472   0%
                                 - file-truename               17,424   0%
                                  - file-truename              17,424   0%
                                   - file-truename              9,236   0%
                                    - file-truename             9,236   0%
                                     - file-truename            1,048   0%
                                        file-truename           1,048   0%
                              - url-hexify-string              12,380   0%
                               - mapconcat                     12,380   0%
                                  #<compiled 0x446c7f65>        12,380   0%
                            - eglot--pos-to-lsp-position         4,224   0%
                               line-number-at-pos               1,056   0%
                      - completion-hilit-commonality            2,032   0%
                       - mapcar                                 2,032   0%
                        - #<compiled 0x430a8d35>                2,032   0%
                           font-lock-prepend-text-property         1,016   0%
                     - completion-pcm-all-completions           1,024   0%
                      - completion-pcm--find-all-completions         1,024   0%
                         completion-pcm--string->pattern         1,024   0%
                - company-call-backend                          5,344   0%
                 - company--force-sync                          5,344   0%
                  - apply                                       5,344   0%
                   - company-call-backend-raw                   5,120   0%
                    - apply                                     5,120   0%
                     - company-yasnippet                        5,120   0%
                        company-grab-symbol                     5,120   0%
           - company-call-backend                                 224   0%
            - company--force-sync                                 224   0%
             - apply                                              224   0%
              - company-call-backend-raw                          224   0%
                 apply                                            224   0%
          - company-call-frontends                            317,504   0%
           - company-tng-frontend                              29,822   0%
              do-after-load-evaluation                         20,180   0%
            - file-truename                                     8,188   0%
               file-truename                                    8,188   0%
            - substitute-env-in-file-name                       1,414   0%
               substitute-env-vars                              1,414   0%
          - company-call-backend                                1,272   0%
           - company--force-sync                                1,272   0%
            - apply                                             1,272   0%
             - company-call-backend-raw                         1,048   0%
              - apply                                           1,048   0%
               - company-dict                                   1,048   0%
                - mapc                                          1,048   0%
                   company-dict--init                           1,048   0%
       - company-post-command                                   7,184   0%
        - company-call-frontends                                7,184   0%
         - company-preview-if-not-tng-frontend                  7,184   0%
          - unless                                              7,184   0%
           - if                                                 7,184   0%
            - company-preview-frontend                          7,184   0%
             - company-preview-show-at-point                    7,184   0%
                company--pre-render                             1,016   0%
      - auto-revert-buffers                                   203,578   0%
       - apply                                                203,578   0%
        - #<compiled 0x4417cff9>                              203,578   0%
         - auto-revert-notify-add-watch                       203,578   0%
          - file-symlink-p                                    199,400   0%
           - ucs-normalize-hfs-nfd-pre-write-conversion       199,400   0%
            - ucs-normalize-HFS-NFD-region                    199,400   0%
               ucs-normalize-region                           199,400   0%
          - file-notify-add-watch                               1,672   0%
           - file-directory-p                                   1,056   0%
            - ucs-normalize-hfs-nfd-pre-write-conversion         1,056   0%
               ucs-normalize-HFS-NFD-region                     1,056   0%
    - redisplay_internal (C function)                          59,684   0%
     - eval                                                    59,684   0%
      + mode-line-right                                        36,508   0%
      + mode-line-remote-icons                                 14,988   0%
        eglot--mode-line-format                                 8,188   0%
   - redisplay                                                674,118   0%
    - redisplay_internal (C function)                         464,364   0%
     + jit-lock-function                                      235,196   0%
     - eval                                                   229,168   0%
      + mode-line-right                                       196,200   0%
      + eglot--mode-line-format                                29,888   0%
        if                                                      1,048   0%
        eyebrowse-mode-line-indicator                           1,016   0%
      + mode-line-modified-icons                                1,016   0%
 + flyspell-word                                               19,696   0%
- jsonrpc--process-filter                                  19,943,945  10%
 - jsonrpc-connection-receive                              18,944,281  10%
  - jsonrpc--log-event                                     12,556,627   6%
   - pp-to-string                                           1,336,324   0%
    - pp-buffer                                               122,120   0%
     - indent-sexp                                            114,728   0%
      - lisp-indent-calc-next                                  42,656   0%
       - calculate-lisp-indent                                 20,480   0%
          lisp-indent-function                                 10,240   0%
      - lisp-indent-initial-state                               4,136   0%
       - lisp-ppss                                              4,136   0%
          syntax-ppss                                           4,136   0%
      generate-new-buffer                                     101,851   0%
    - #<compiled 0x44904c75>                                   11,260   0%
     - kill-buffer                                             11,260   0%
      - posframe-auto-delete                                    8,188   0%
         posframe-delete-frame                                  8,188   0%
        tramp-flush-file-function                               3,072   0%
  - #<compiled 0x44697db9>                                  6,295,719   3%
   - apply                                                  6,295,719   3%
    - #<compiled 0x446a0dd5>                                6,295,719   3%
     - eglot--hover-info                                    6,111,224   3%
      - mapconcat                                           6,109,192   3%
       - eglot--format-markup                               6,107,057   3%
        - gfm-mode                                          2,832,249   1%
         - run-mode-hooks                                   1,871,965   1%
          - run-hooks                                       1,704,923   0%
           - yas-global-mode-enable-in-buffers              1,585,323   0%
            - yas-minor-mode-on                             1,585,323   0%
             - yas-minor-mode                               1,585,323   0%
              - yas--load-pending-jits                      1,585,203   0%
               - #<compiled 0x432d1581>                     1,585,203   0%
                - apply                                     1,585,203   0%
                 - yas--load-directory-1                    1,585,203   0%
                  - yas--load-directory-2                   1,567,631   0%
                   - yas--parse-template                      486,124   0%
                    - yas--calculate-group                    254,608   0%
                     - locate-dominating-file                 254,608   0%
                        abbreviate-file-name                   52,296   0%
                      match-string-no-properties               36,288   0%
                   - insert-file-contents                     390,556   0%
                    - set-auto-coding                         364,932   0%
                     - find-auto-coding                       364,932   0%
                        auto-coding-alist-lookup              179,816   0%
                        auto-coding-regexp-alist-lookup       134,212   0%
                        sgml-html-meta-auto-coding-function        25,624   0%
                        sgml-xml-auto-coding-function          24,576   0%
                      format-decode                            25,624   0%
                   - yas--subdirs                             115,712   0%
                    - directory-files                          82,712   0%
                     - ucs-normalize-hfs-nfd-post-read-conversion        82,712   0%
                      - ucs-normalize-HFS-NFC-region           82,712   0%
                         ucs-normalize-region                  82,712   0%
                    - cl-remove-if                             18,524   0%
                     - apply                                   18,524   0%
                      - cl-remove                              18,524   0%
                         #<compiled 0x4487daad>                18,524   0%
                   - yas-define-snippets                       18,660   0%
                    - yas--define-snippets-1                   18,660   0%
                     - yas--update-template                    18,660   0%
                      - yas--update-template-menu               4,240   0%
                         yas--delete-from-keymap                2,112   0%
                        yas--add-template                       4,136   0%
                     generate-new-buffer                        3,170   0%
                     yas--load-yas-setup-file                   1,048   0%
                   - #<compiled 0x4487f669>                     1,024   0%
                    - kill-buffer                               1,024   0%
                       tramp-flush-file-function                1,024   0%
                  - load                                        2,048   0%
                   - substitute-env-in-file-name                2,048   0%
                      substitute-env-vars                       2,048   0%
           + smartparens-global-mode-enable-in-buffers        111,672   0%
           + evil-mode-enable-in-buffers                        7,928   0%
          - apply                                             167,042   0%
           - run-hooks                                        167,042   0%
            + readable-mode                                   152,431   0%
            + flyspell-mode                                     8,216   0%
            + bug-reference-mode                                5,171   0%
              visual-line-mode                                    120   0%
            + add-evil-normal-state-entry-hook--markdown-mode            40   0%
            + add-evil-insert-state-entry-hook--markdown-mode            40   0%
         + do-after-load-evaluation                           429,036   0%
         + easy-menu-do-define                                 52,664   0%
         + require                                             35,094   0%
         + defconst                                            16,376   0%
         + markdown-make-header-faces                          12,000   0%
         + byte-code                                            8,308   0%
         + markdown-mode                                        6,838   0%
         + defvar                                               3,048   0%
         + substitute-env-in-file-name                          1,024   0%
        + typescript-mode                                   2,609,126   1%
        + font-lock-ensure                                    150,711   0%
        + #<compiled 0x446a0de9>                                3,232   0%
          generate-new-buffer                                   3,183   0%
          flycheck-handle-change                                2,048   0%
        + markdown-gfm-checkbox-after-change-function           1,024   0%
     + eldoc-message                                          179,383   0%
  - #<compiled 0x43fd0bfd>                                     91,935   0%
   - apply                                                     91,935   0%
    - eglot-handle-notification                                91,935   0%
     - apply                                                   91,935   0%
      - #<compiled 0x41300e75>                                 91,935   0%
       - apply                                                 91,935   0%
        - #<compiled 0x40564289>                               91,935   0%
         - find-buffer-visiting                                44,484   0%
            file-truename                                      38,340   0%
            abbreviate-file-name                                6,144   0%
         - eglot--uri-to-path                                  37,235   0%
          - url-generic-parse-url                              27,821   0%
             generate-new-buffer                                3,183   0%
            url-unhex-string                                    3,072   0%
         - #<compiled 0x430a8a7d>                              10,216   0%
          - apply                                              10,216   0%
           - flymake--handle-report                            10,216   0%
              flymake--log-1                                    3,000   0%
              flymake--diagnostics-buffer-name                  3,000   0%
            - flymake-delete-own-overlays                          80   0%
               flymake--overlays                                   80   0%
 - jsonrpc--json-read                                         698,017   0%
  - json-read                                                 698,017   0%
   - json-read-object                                         698,017   0%
    - json-read                                               689,829   0%
     - json-read-object                                       681,641   0%
      - json-read                                             665,265   0%
         json-read-number                                       4,354   0%
         json-read-string                                       1,541   0%
   generate-new-buffer                                        100,795   0%
 - #<compiled 0x44904ee1>                                      11,440   0%
  - kill-buffer                                                 8,272   0%
     tramp-flush-file-function                                  8,272   0%
- company-post-command                                     19,929,759  10%
 - company--perform                                        19,924,597  10%
  - company--continue                                      19,924,597  10%
   - company-calculate-candidates                          19,924,597  10%
    - company--fetch-candidates                            19,924,597  10%
     - company-call-backend-raw                            19,924,597  10%
      - apply                                              19,924,597  10%
       - company--multi-backend-adapter                    19,924,597  10%
        - company--multi-backend-adapter-candidates        19,924,597  10%
         - company-call-backend                            19,922,549  10%
          - company--force-sync                            19,922,549  10%
           - apply                                         19,922,549  10%
            - company-call-backend-raw                     19,922,549  10%
             - apply                                       19,922,549  10%
              - company--multi-backend-adapter             19,881,353  10%
               - apply                                     19,870,017  10%
                - company-capf                             19,870,017  10%
                 - company--capf-post-completion           19,870,017  10%
                  - try-completion                         19,810,093  10%
                   - #<compiled 0x4051eff1>                19,810,093  10%
                    - #<compiled 0x4051e7f1>               19,810,093  10%
                     - #<compiled 0x404a8b1d>              19,810,093  10%
                      - jsonrpc-request                    19,692,679  10%
                       - apply                             19,692,679  10%
                        - #<compiled 0x41db6fc9>           16,419,614   9%
                         - accept-process-output           15,324,241   8%
                          - jsonrpc--process-filter        15,324,241   8%
                           - jsonrpc-connection-receive     9,150,154   5%
                            - jsonrpc--log-event            8,813,218   4%
                             - pp-to-string                 4,784,921   2%
                              - pp-buffer                   2,949,483   1%
                               - indent-sexp                2,899,299   1%
                                - indent-line-to              246,128   0%
                                   back-to-indentation        246,128   0%
                                - lisp-indent-calc-next       242,824   0%
                                 - calculate-lisp-indent        42,184   0%
                                    lisp-indent-function        20,480   0%
                                    backward-prefix-chars         1,640   0%
                                    parse-partial-sexp          1,640   0%
                                - lisp-indent-initial-state        12,408   0%
                                 - lisp-ppss                   12,408   0%
                                    syntax-ppss                12,408   0%
                                 down-list                     49,128   0%
                                generate-new-buffer            27,586   0%
                            - #<compiled 0x43fd0bfd>          336,936   0%
                             - apply                          336,936   0%
                              + eglot-handle-notification       336,936   0%
                           - jsonrpc--json-read             5,891,343   3%
                            - json-read                     5,891,343   3%
                             - json-read-object             5,891,343   3%
                              - json-read                   5,891,343   3%
                               - json-read-object           5,891,343   3%
                                - json-read                 5,883,155   3%
                                 - json-read-array          5,843,043   3%
                                  - json-read               5,835,403   3%
                                   - json-read-object       5,835,403   3%
                                    - json-read             4,323,071   2%
                                     - json-read-object     3,803,503   2%
                                      - json-read           1,868,560   1%
                                         json-read-number       228,736   0%
                                      - json-add-to-object         8,200   0%
                                         intern                 1,640   0%
                                       json-read-number        38,384   0%
                                      json-add-to-object         1,640   0%
                                   json-read-number             1,264   0%
                                   json-read-keyword            1,024   0%
                             generate-new-buffer               27,586   0%
                         - jsonrpc--async-request-1             6,557   0%
                          - jsonrpc-connection-send             6,557   0%
                           - apply                              6,557   0%
                            - #<compiled 0x41dba225>            6,557   0%
                             - jsonrpc--log-event               6,005   0%
                              - pp-to-string                    5,005   0%
                                 generate-new-buffer            1,061   0%
                               - pp-buffer                        704   0%
                                  indent-sexp                     704   0%
                        - #<compiled 0x41dc1135>            3,273,065   1%
                         - eglot--signal-textDocument/didChange     3,273,065   1%
                          - jsonrpc-notify                  3,271,113   1%
                           - jsonrpc-connection-send        3,271,113   1%
                            - apply                         3,271,113   1%
                             - #<compiled 0x41dba225>       3,271,113   1%
                              - jsonrpc--log-event          3,033,457   1%
                               - pp-to-string                  62,290   0%
                                - pp-buffer                    47,992   0%
                                 - indent-sexp                 47,992   0%
                                  - lisp-indent-calc-next        47,288   0%
                                   - calculate-lisp-indent        42,008   0%
                                      lisp-indent-function        20,480   0%
                                  generate-new-buffer           1,061   0%
                              - jsonrpc--json-encode          228,546   0%
                               - json-encode                  228,546   0%
                                - json-encode-list            228,546   0%
                                 - json-encode-plist          224,066   0%
                                  - json-encode               137,648   0%
                                   - json-encode-list         129,460   0%
                                    - json-encode-plist        86,972   0%
                                     - json-encode             40,584   0%
                                        json-encode-array        20,264   0%
                                     - json-encode-key         24,388   0%
                                      - json-read-from-string        22,276   0%
                                         generate-new-buffer        21,220   0%
                                         #<compiled 0x446c8005>         1,056   0%
                                       json-join               22,000   0%
                                   - json-encode-string         8,188   0%
                                      apply                     8,188   0%
                                  - json-encode-key            63,834   0%
                                   - json-read-from-string        44,222   0%
                                      generate-new-buffer        31,830   0%
                                    - #<compiled 0x404a8bf9>        12,392   0%
                                     - kill-buffer             11,336   0%
                                        tramp-flush-file-function        10,288   0%
                                      - posframe-auto-delete         1,048   0%
                                         posframe-delete-frame         1,048   0%
                                   - json-encode               11,424   0%
                                    - json-encode-string        11,424   0%
                                       apply                    1,048   0%
                                    json-join                  22,584   0%
                      - mapcar                                101,600   0%
                       - #<compiled 0x41dc2dd1>               101,600   0%
                        - apply                               101,600   0%
                           #<compiled 0x41dc2dc5>             101,600   0%
                      - eglot--TextDocumentPositionParams        15,814   0%
                       - eglot--TextDocumentIdentifier         15,814   0%
                        - eglot--path-to-uri                   15,814   0%
                         - url-hexify-string                    8,188   0%
                          - mapconcat                           8,188   0%
                             #<compiled 0x405b30f1>             8,188   0%
                           file-truename                        7,626   0%
                  - #<compiled 0x41dc2e75>                     58,900   0%
                   - eglot-eldoc-function                      58,900   0%
                    - jsonrpc-async-request                    58,900   0%
                     - apply                                   58,900   0%
                      - jsonrpc--async-request-1               58,900   0%
                       - jsonrpc-connection-send               58,900   0%
                        - apply                                58,900   0%
                         - #<compiled 0x41dba225>              58,900   0%
                          - jsonrpc--json-encode               35,492   0%
                           - json-encode                       35,492   0%
                            - json-encode-list                 35,492   0%
                             - json-encode-plist               35,492   0%
                              - json-encode                    20,788   0%
                               - json-encode-list              18,788   0%
                                - json-encode-plist            18,788   0%
                                 - json-encode-key             16,676   0%
                                  - json-read-from-string         8,488   0%
                                     generate-new-buffer         8,488   0%
                                    json-encode                 8,188   0%
                                 - json-encode                  2,112   0%
                                  - json-encode-list            2,112   0%
                                   - json-encode-plist          2,112   0%
                                      json-encode-key           2,112   0%
                                 json-encode-number             2,000   0%
                              - json-encode-key                14,704   0%
                               - json-read-from-string         12,624   0%
                                  generate-new-buffer           8,488   0%
                                - #<compiled 0x44647be5>         4,136   0%
                                 - kill-buffer                  4,136   0%
                                    tramp-flush-file-function         4,136   0%
                               - json-encode                    1,024   0%
                                  json-encode-string            1,024   0%
                          - jsonrpc--log-event                 14,120   0%
                           - pp-to-string                      12,120   0%
                            - pp-buffer                         3,520   0%
                             - indent-sexp                      3,520   0%
                                lisp-indent-calc-next           1,056   0%
                              generate-new-buffer               2,122   0%
                  - company--capf-data                          1,024   0%
                   - company--capf-data-real                    1,024   0%
                    - run-hook-wrapped                          1,024   0%
                     - completion--capf-wrapper                 1,024   0%
                      - eglot-completion-at-point               1,024   0%
                       - bounds-of-thing-at-point               1,024   0%
                        - #<compiled 0x405ae1f1>                1,024   0%
                         - forward-thing                        1,024   0%
                            forward-symbol                      1,024   0%
               - company--force-sync                           11,336   0%
                - apply                                        11,336   0%
                 - company-capf                                11,336   0%
                  - company--capf-data                         11,336   0%
                   - company--capf-data-real                   11,336   0%
                    - run-hook-wrapped                         11,336   0%
                     - completion--capf-wrapper                11,336   0%
                      - eglot-completion-at-point              11,336   0%
                       - bounds-of-thing-at-point              11,336   0%
                        - #<compiled 0x43784119>               11,336   0%
                         - forward-thing                       11,336   0%
                            forward-symbol                     11,336   0%
              - company-files                                  36,076   0%
               - company-files--grab-existing-name             36,076   0%
                - company-grab-line                            36,076   0%
                 - company-grab                                36,076   0%
                    looking-back                               36,076   0%
              - company-yasnippet                               5,120   0%
                 company-grab-symbol                            5,120   0%
         - company-capf                                         2,048   0%
          - completion-all-completions                          2,048   0%
           - completion--nth-completion                         2,048   0%
            - completion--some                                  2,048   0%
             - #<compiled 0x40522bf1>                           2,048   0%
              - completion-pcm-all-completions                  2,048   0%
               - completion-pcm--find-all-completions           2,048   0%
                  completion-pcm--string->pattern               2,048   0%
 - company-call-frontends                                       5,104   0%
  - company-preview-if-not-tng-frontend                         5,104   0%
   - unless                                                     5,104   0%
    - if                                                        5,104   0%
     - company-preview-frontend                                 5,104   0%
        company-preview-show-at-point                           4,088   0%
 - company-abort                                                   58   0%
  - company-cancel                                                 58   0%
   - company-call-frontends                                        58   0%
    - company-echo-metadata-frontend                               58   0%
     - company-echo-hide                                           58   0%
        company-echo-show                                          58   0%
- command-execute                                           9,032,779   4%
 - call-interactively                                       9,032,779   4%
  - funcall-interactively                                   9,032,779   4%
   - counsel-M-x                                            8,024,779   4%
    + ivy-read                                              7,555,915   4%
    + counsel--M-x-externs                                    468,864   0%
   + self-insert-command                                      658,080   0%
   + delete-backward-char                                     325,056   0%
   + move-end-of-line                                          13,574   0%
   + company-complete-selection                                11,290   0%
+ timer-event-handler                                       1,961,742   1%
+ redisplay_internal (C function)                             239,768   0%
+ direnv--maybe-update-environment                            151,932   0%
+ ...                                                          39,230   0%
+ symbol-overlay-post-command                                  39,172   0%
+ winner-save-old-configurations                               15,664   0%
+ #<lambda 0x748dc7d3eb>                                       10,370   0%
+ sp--save-pre-command-state                                    5,192   0%
  undefined                                                       418   0%
joaotavora commented 6 years ago

Thanks for the profiler data. It does help: there are some things that stand out.

  1. First I don't understand what flyspellis doing here and how it might be inteferering. It's probably a red herring, but can you turn off flyspell-mode or flyspell-prog-mode?

  2. The javascript-typescript-langserver is in the habit of sending all possible completions every time (and letting the client filter them according to the prefix). It's probably sending you a monster list of completions because your project is big and this takes a long time to compute the first time (and still a considerable amount the second time around).

  3. Regardless, back in Eglot, we seem to be spending a lot of time just registering the gigantic completions message in its events buffer (which is designed for debug). It shouldn't be doing this. I have a fix for a related problem (#41) that I will push very soon and also consider your situation. In the meantime, can you try evaluating the following definition and profiling again?

(defun jsonrpc--log-event (_connection _message &optional type)
  "A NOOP just for issue 61"
  nil)
terlar commented 6 years ago

Thanks, this seems to have improved the situation, I disabled the flyspell and also added that function override:

This is the new output:

- company-post-command                                     21,824,412  48%
 - company--perform                                        21,811,116  48%
  - company--continue                                      21,811,116  48%
   - company-calculate-candidates                          21,811,116  48%
    - company--fetch-candidates                            21,811,116  48%
     - company-call-backend-raw                            21,811,116  48%
      - apply                                              21,811,116  48%
       - company--multi-backend-adapter                    21,811,116  48%
        - company--multi-backend-adapter-candidates        21,811,116  48%
         - company-capf                                    21,771,190  48%
          - completion-all-completions                     21,771,190  48%
           - completion--nth-completion                    21,771,190  48%
            - completion--some                             21,771,190  48%
             - #<compiled 0x4475af21>                      21,771,190  48%
              - completion-basic-all-completions           21,771,190  48%
               - completion-pcm--all-completions           21,771,190  48%
                - all-completions                          21,771,190  48%
                 - #<compiled 0x4475aecd>                  21,771,190  48%
                  - #<compiled 0x4475aea5>                 21,771,190  48%
                   - #<compiled 0x4475ae81>                21,771,190  48%
                    - jsonrpc-request                      21,047,556  46%
                     - apply                               21,047,556  46%
                      - #<compiled 0x4414806d>             20,844,892  46%
                       - accept-process-output             12,473,437  27%
                        - jsonrpc--process-filter           6,965,025  15%
                         - jsonrpc-connection-receive       3,310,071   7%
                          - #<compiled 0x43fe8ead>          3,016,350   6%
                           - apply                          3,016,350   6%
                            - #<compiled 0x4114edf1>        3,016,350   6%
                             - eglot--hover-info            3,014,716   6%
                              - mapconcat                   3,014,716   6%
                               - eglot--format-markup       3,014,716   6%
                                - typescript-mode           2,592,988   5%
                                 - run-mode-hooks           2,458,888   5%
                                  - apply                   2,334,404   5%
                                   - run-hooks              2,334,404   5%
                                    - flycheck-mode         2,163,102   4%
                                     - run-hooks            2,162,742   4%
                                      - flycheck-plantuml-setup       296,928   0%
                                       - byte-code            264,918   0%
                                        - require              48,502   0%
                                         - do-after-load-evaluation        26,666   0%
                                          - run-hook-with-args         7,186   0%
                                           - eval-after-load-helper         7,186   0%
                                            - #<lambda 0x310ca9c>         7,186   0%
                                             - progn            7,186   0%
                                              - progn           7,186   0%
                                               - req-package-loaded         7,186   0%
                                                - req-package--log-info         7,186   0%
                                                 - apply         7,186   0%
                                                  - log4e--logging         7,186   0%
                                                   - replace-regexp-in-string         5,136   0%
                                                      apply         1,016   0%
                                         - #<compiled 0x440236c1>        19,692   0%
                                          - apply              19,692   0%
                                             edebug--read        19,692   0%
                                         - file-truename         2,096   0%
                                          - file-truename         2,096   0%
                                           - file-truename         2,096   0%
                                            - file-truename         2,096   0%
                                             - file-truename         2,096   0%
                                                file-truename         1,048   0%
                                         - defvar                  48   0%
                                          - byte-code              48   0%
                                             image-type-available-p            48   0%
                                        - flycheck-define-command-checker        10,456   0%
                                         - apply               10,456   0%
                                          - flycheck-define-generic-checker         9,408   0%
                                           - flycheck-current-load-file         9,408   0%
                                            - file-name-sans-extension         9,408   0%
                                               file-name-sans-versions         1,184   0%
                                       - do-after-load-evaluation        27,842   0%
                                        - run-hook-with-args         8,362   0%
                                         - eval-after-load-helper         8,362   0%
                                          - #<lambda 0x310ca9c>         8,362   0%
                                           - progn              8,362   0%
                                            - progn             8,362   0%
                                             - req-package-loaded         8,362   0%
                                              - req-package--log-info         8,362   0%
                                               - apply          8,362   0%
                                                - log4e--logging         8,362   0%
                                                   replace-regexp-in-string         3,072   0%
                                       - file-truename          2,096   0%
                                        - file-truename         2,096   0%
                                         - file-truename         2,096   0%
                                          - file-truename         2,096   0%
                                           - file-truename         1,048   0%
                                            - file-truename         1,048   0%
                                               file-truename         1,048   0%
                                       - #<compiled 0x440236c1>         1,048   0%
                                        - apply                 1,048   0%
                                           edebug--read         1,048   0%
                                       - substitute-env-in-file-name         1,024   0%
                                          substitute-env-vars         1,024   0%
                                      + flycheck-posframe-mode       155,106   0%
                                      + flycheck-yamllint-setup        69,882   0%
                                      + flycheck-elm-setup        48,334   0%
                                      + flycheck-mix-setup        46,254   0%
                                      + flycheck-credo-setup        45,230   0%
                                      + flycheck-rust-setup        41,102   0%
                                      + flycheck-rebar3-setup        34,946   0%
                                     + flycheck-clear             320   0%
                                       add-hook                    40   0%
                                    + rainbow-identifiers-mode        56,610   0%
                                    + hs-minor-mode             2,048   0%
                                    + bug-reference-prog-mode         2,048   0%
                                    + hl-line-mode              1,408   0%
                                  - run-hooks                 124,484   0%
                                   + yas-global-mode-enable-in-buffers        58,569   0%
                                   + company-quickhelp-mode-enable-in-buffers        45,075   0%
                                   + evil-mode-enable-in-buffers        20,840   0%
                                 - #<compiled 0x440236c1>        74,612   0%
                                  - apply                      74,612   0%
                                     edebug--read              74,612   0%
                                 - defconst                    30,852   0%
                                  - typescript--regexp-opt-symbol        28,756   0%
                                   - regexp-opt                28,756   0%
                                    - regexp-opt-group         27,708   0%
                                     - regexp-opt-group        27,708   0%
                                      - regexp-opt-group        26,660   0%
                                       - regexp-opt-group        26,660   0%
                                        - regexp-opt-group        17,424   0%
                                         - regexp-opt-group        17,424   0%
                                          - regexp-opt-group        16,376   0%
                                           - regexp-opt-group         8,188   0%
                                            - regexp-opt-group         8,188   0%
                                             - regexp-opt-group         8,188   0%
                                              - regexp-opt-group         8,188   0%
                                                 mapcar         8,188   0%
                                          mapcar                9,236   0%
                                        mapcar                  1,048   0%
                                  - byte-code                   1,048   0%
                                   - typescript--make-framework-matcher         1,048   0%
                                    - byte-compile              1,048   0%
                                     - #<compiled 0x41244949>         1,048   0%
                                      - byte-compile-top-level         1,048   0%
                                       - byte-compile-form         1,048   0%
                                        - byte-compile-function-form         1,048   0%
                                         - byte-compile-lambda         1,048   0%
                                          - byte-compile-top-level         1,048   0%
                                           - byte-compile-out-toplevel         1,048   0%
                                            - byte-compile-lapcode         1,048   0%
                                               apply            1,048   0%
                                   do-after-load-evaluation        19,776   0%
                                 - defvar                       4,136   0%
                                  - byte-code                   4,136   0%
                                     c-populate-syntax-table         4,136   0%
                                   c-setup-paragraph-variables         2,048   0%
                                 - substitute-env-in-file-name         1,388   0%
                                    substitute-env-vars         1,388   0%
                                   byte-code                       80   0%
                                - font-lock-ensure             61,486   0%
                                 - #<compiled 0x40c714f3>        61,486   0%
                                  - font-lock-default-fontify-buffer        61,486   0%
                                   - font-lock-fontify-region        61,486   0%
                                    - font-lock-default-fontify-region        61,486   0%
                                     - font-lock-fontify-keywords-region        61,486   0%
                                        #<compiled 0x413432f1>         2,552   0%
                                        #<compiled 0x413426f1>         2,298   0%
                                        typescript--tslint-flag-matcher         2,048   0%
                                        typescript--class-decl-matcher         2,048   0%
                                        #<compiled 0x413442f1>         2,048   0%
                                        compact-docstrings--matcher         2,048   0%
                                        rainbow-identifiers--matcher         2,048   0%
                                - #<compiled 0x4114f5f1>         6,344   0%
                                 - kill-buffer                  6,344   0%
                                    tramp-flush-file-function         6,184   0%
                                  - flycheck-teardown             160   0%
                                   - flycheck-clear               160   0%
                                    - flycheck-delete-all-overlays           160   0%
                                       flycheck-overlays-in           160   0%
                                  generate-new-buffer           2,122   0%
                                  flycheck-handle-change         2,048   0%
                             - eldoc-message                      618   0%
                              - eldoc-minibuffer-message           618   0%
                                 apply                            618   0%
                          - #<compiled 0x4415a231>            271,606   0%
                           - apply                            271,606   0%
                            - eglot-handle-notification       271,606   0%
                             - apply                          267,470   0%
                              - #<compiled 0x44767171>        267,470   0%
                               - apply                        267,470   0%
                                - #<compiled 0x44159cd1>       267,470   0%
                                 - eglot--uri-to-path         127,962   0%
                                  - url-generic-parse-url        93,750   0%
                                     generate-new-buffer        10,610   0%
                                    url-unhex-string           10,960   0%
                                 - find-buffer-visiting       119,348   0%
                                  - file-truename              98,730   0%
                                   - file-truename             82,076   0%
                                    - file-truename            79,980   0%
                                     - file-truename           63,604   0%
                                      - file-truename          39,040   0%
                                       - file-truename         37,992   0%
                                        - file-truename        19,520   0%
                                         - file-truename        10,284   0%
                                          - file-truename         2,096   0%
                                             file-truename         1,048   0%
                                    abbreviate-file-name        20,618   0%
                                 - #<compiled 0x44761175>        20,160   0%
                                  - apply                      20,160   0%
                                   - flymake--handle-report        20,160   0%
                                      flymake--log-1           10,000   0%
                                      flymake--diagnostics-buffer-name        10,000   0%
                                    - flymake-delete-own-overlays           160   0%
                                       flymake--overlays           160   0%
                             - cl--generic-cache-miss           4,136   0%
                              - cl--generic-make-next-function         4,136   0%
                                 #<compiled 0x41016b79>         4,136   0%
                          - jsonrpc--warn                      22,115   0%
                           - display-warning                   15,163   0%
                            - special-mode                     12,374   0%
                             - run-mode-hooks                  12,374   0%
                              - run-hooks                      12,374   0%
                               - global-company-mode-enable-in-buffers         8,188   0%
                                - company-mode-on               8,188   0%
                                 - company-mode                 8,188   0%
                                  - run-hooks                   8,188   0%
                                   - company-quickhelp-mode         8,188   0%
                                      company-quickhelp-local-mode         8,188   0%
                               - evil-mode-enable-in-buffers         4,186   0%
                                - evil-initialize               4,186   0%
                                 - evil-local-mode              4,186   0%
                                  - evil-initialize-state         2,118   0%
                                   - evil-change-to-initial-state         2,118   0%
                                    - evil-change-state         2,118   0%
                                     - evil-emacs-state         2,118   0%
                                      - evil-normalize-keymaps         2,118   0%
                                         evil-auxiliary-keymap-p         1,094   0%
                                         evil-minor-mode-keymap-p         1,024   0%
                                  - evil-disabled-buffer-p         2,068   0%
                                     evil-initial-state-for-buffer-name         2,068   0%
                            - newline                           1,728   0%
                             - self-insert-command              1,728   0%
                                #<compiled 0x44710571>          1,728   0%
                           - apply                              4,908   0%
                            - jsonrpc--message                  2,908   0%
                               apply                            2,000   0%
                         - jsonrpc--json-read               1,249,221   2%
                          - json-read                       1,249,221   2%
                           - json-read-object               1,249,221   2%
                            - json-read                     1,215,225   2%
                             - json-read-object             1,168,859   2%
                              - json-read                   1,114,491   2%
                                 json-read-string             389,413   0%
                                 json-read-array               45,840   0%
                                 json-read-number              30,420   0%
                                 json-read-keyword              9,306   0%
                               json-read-number                 2,282   0%
                           generate-new-buffer                401,045   0%
                         - #<compiled 0x4475c269>              58,648   0%
                          - kill-buffer                        48,088   0%
                             tramp-flush-file-function         45,992   0%
                           - posframe-auto-delete               2,096   0%
                              posframe-delete-frame             2,096   0%
                        - timer-event-handler                 542,109   1%
                         - apply                              542,109   1%
                          - diff-hl-flydiff-update            443,457   0%
                           - diff-hl-update                   443,457   0%
                            - diff-hl-changes                 442,241   0%
                             - diff-hl-changes-buffer         429,065   0%
                              - apply                         429,065   0%
                               - diff-hl-flydiff-buffer-with-head       429,065   0%
                                - diff-no-select              393,094   0%
                                 - diff-file-local-copy       313,718   0%
                                  - make-temp-file            272,368   0%
                                   - make-temp-file-internal       271,868   0%
                                    - ucs-normalize-hfs-nfd-pre-write-conversion       193,872   0%
                                     - ucs-normalize-HFS-NFD-region       193,872   0%
                                        ucs-normalize-region       193,872   0%
                                    - ucs-normalize-hfs-nfd-post-read-conversion        77,996   0%
                                     - ucs-normalize-HFS-NFC-region        77,996   0%
                                        ucs-normalize-region        77,996   0%
                                  - write-region               29,728   0%
                                   - select-safe-coding-system        29,728   0%
                                    - find-auto-coding         29,728   0%
                                       auto-coding-alist-lookup        14,336   0%
                                       auto-coding-regexp-alist-lookup        10,240   0%
                                       sgml-xml-auto-coding-function         2,048   0%
                                       sgml-html-meta-auto-coding-function         2,048   0%
                                 + diff-mode                   54,420   0%
                                 + mapcar                      20,472   0%
                                + diff-hl-flydiff/working-revision        23,687   0%
                                + diff-hl-flydiff-create-revision        12,284   0%
                               diff-end-of-hunk                 4,096   0%
                               diff-count-matches               4,096   0%
                             + diff-beginning-of-hunk           2,600   0%
                              diff-hl-add-highlighting          1,056   0%
                              diff-hl-remove-overlays             160   0%
                          - #<compiled 0x400f55e1>             74,232   0%
                           - eldoc-print-current-symbol-info        74,232   0%
                            - #<compiled 0x43f45981>           74,232   0%
                             - apply                           74,232   0%
                              - eglot-eldoc-function           74,232   0%
                               - jsonrpc-async-request         53,720   0%
                                - apply                        53,720   0%
                                 - jsonrpc--async-request-1        53,720   0%
                                  - jsonrpc-connection-send        53,720   0%
                                   - apply                     53,720   0%
                                    - #<compiled 0x44256ff1>        53,720   0%
                                     - jsonrpc--json-encode        51,528   0%
                                      - json-encode            51,528   0%
                                       - json-encode-list        51,528   0%
                                        - json-encode-plist        51,528   0%
                                         - json-encode-key        26,328   0%
                                          - json-read-from-string        22,168   0%
                                             generate-new-buffer        16,976   0%
                                             #<compiled 0x447b4a21>         1,056   0%
                                          - json-encode         2,048   0%
                                             json-encode-string         2,048   0%
                                         - json-encode         25,200   0%
                                          - json-encode-list        21,200   0%
                                           - json-encode-plist        21,200   0%
                                            - json-encode-key        20,144   0%
                                             - json-read-from-string        19,088   0%
                                                generate-new-buffer        16,976   0%
                                                #<compiled 0x43fe9011>         2,112   0%
                                            - json-encode         1,056   0%
                                             - json-encode-list         1,056   0%
                                              - json-encode-plist         1,056   0%
                                                 json-encode-key         1,056   0%
                                            json-encode-number         4,000   0%
                               - eglot--TextDocumentPositionParams        16,376   0%
                                - eglot--TextDocumentIdentifier        16,376   0%
                                 - eglot--path-to-uri          16,376   0%
                                  - url-hexify-string           8,188   0%
                                   - mapconcat                  8,188   0%
                                      #<compiled 0x44761189>         8,188   0%
                                    file-truename               8,188   0%
                          - symbol-overlay-maybe-put-temp        16,420   0%
                           - symbol-overlay-get-symbol         14,372   0%
                            - thing-at-point                   14,372   0%
                             - bounds-of-thing-at-point        14,372   0%
                              - #<compiled 0x4499b809>         10,236   0%
                               - forward-thing                 10,236   0%
                                  forward-symbol                2,048   0%
                          - #<compiled 0x4423a9f5>              8,000   0%
                           - flymake--log-1                     4,000   0%
                              apply                             2,000   0%
                           - flymake-start                      4,000   0%
                            - run-hook-wrapped                  4,000   0%
                             - #<compiled 0x44761151>           4,000   0%
                              - flymake--run-backend            2,000   0%
                                 flymake--log-1                 2,000   0%
                                flymake--log-1                  2,000   0%
                       - jsonrpc--async-request-1             281,871   0%
                        - jsonrpc-connection-send             277,735   0%
                         - apply                              277,735   0%
                          - #<compiled 0x44256ff1>            277,735   0%
                           - jsonrpc--json-encode             264,597   0%
                            - json-encode                     264,597   0%
                             - json-encode-list               264,597   0%
                              - json-encode-plist             264,597   0%
                               - json-encode                  204,461   0%
                                - json-encode-list            193,461   0%
                                 - json-encode-plist          193,461   0%
                                  - json-encode               160,883   0%
                                   - json-encode-list         160,883   0%
                                    - json-encode-plist       160,883   0%
                                     - json-encode-key        106,507   0%
                                      - json-read-from-string        95,167   0%
                                         generate-new-buffer        83,819   0%
                                       - #<compiled 0x4475c13d>        11,348   0%
                                        - kill-buffer           9,236   0%
                                         - posframe-auto-delete         9,236   0%
                                            posframe-delete-frame         9,236   0%
                                        json-encode            10,284   0%
                                     - json-encode             54,376   0%
                                        json-encode-number        38,000   0%
                                      - json-encode-string        16,376   0%
                                         apply                 16,376   0%
                                  - json-encode-key            24,390   0%
                                   - json-read-from-string        23,342   0%
                                      generate-new-buffer        23,342   0%
                                   - json-encode                1,048   0%
                                    - json-encode-string         1,048   0%
                                       apply                    1,048   0%
                                    json-join                   8,188   0%
                                  json-encode-number           11,000   0%
                               - json-encode-key               60,136   0%
                                - json-read-from-string        59,088   0%
                                   generate-new-buffer         47,732   0%
                                   json-read                    8,188   0%
                                   #<compiled 0x4475c04d>         3,168   0%
                      - #<compiled 0x44247391>                202,664   0%
                       - eglot--signal-textDocument/didChange       202,664   0%
                        - jsonrpc-notify                      124,424   0%
                         - jsonrpc-connection-send            124,424   0%
                          - apply                             124,424   0%
                           - #<compiled 0x44256ff1>           123,376   0%
                            - jsonrpc--json-encode             41,368   0%
                             - json-encode                     41,368   0%
                                json-encode-list               41,368   0%
                        - eglot--VersionedTextDocumentIdentifier        60,656   0%
                         - eglot--TextDocumentIdentifier        60,656   0%
                          - eglot--path-to-uri                 52,468   0%
                           - url-hexify-string                 32,948   0%
                            - mapconcat                        32,948   0%
                               #<compiled 0x43fb62f1>          32,948   0%
                           - file-truename                     19,520   0%
                            - file-truename                    11,332   0%
                             - file-truename                    9,236   0%
                                file-truename                   9,236   0%
                    - mapcar                                  607,568   1%
                     - #<compiled 0x4423341d>                 607,568   1%
                      - apply                                 607,568   1%
                         #<compiled 0x44233409>               607,568   1%
                    - eglot--TextDocumentPositionParams       116,066   0%
                     - eglot--TextDocumentIdentifier          116,066   0%
                      - eglot--path-to-uri                    107,878   0%
                       - file-truename                        103,686   0%
                        - file-truename                        35,896   0%
                         - file-truename                       33,800   0%
                          - file-truename                      25,612   0%
                           - file-truename                     25,612   0%
                            - file-truename                    17,424   0%
                             - file-truename                   17,424   0%
                              - file-truename                  17,424   0%
                                 file-truename                  1,048   0%
                       - url-hexify-string                      4,192   0%
                        - mapconcat                             4,192   0%
                           #<compiled 0x43fa0871>               4,192   0%
         - company-call-backend                                39,926   0%
          - company--force-sync                                39,926   0%
           - apply                                             39,926   0%
            - company-call-backend-raw                         39,926   0%
             - apply                                           39,926   0%
              - company-files                                  32,758   0%
               - company-files--grab-existing-name             32,758   0%
                - company-grab-line                            32,758   0%
                 - company-grab                                32,758   0%
                    looking-back                               31,710   0%
              - company-yasnippet                               7,168   0%
                 company-grab-symbol                            7,168   0%
 - company-call-frontends                                      13,296   0%
  - company-preview-if-not-tng-frontend                        13,296   0%
   - unless                                                    13,296   0%
    - if                                                       13,296   0%
     - company-preview-frontend                                13,296   0%
      - company-preview-show-at-point                          13,296   0%
         company--pre-render                                    5,080   0%
- command-execute                                          16,028,198  35%
 - call-interactively                                      16,028,198  35%
  - funcall-interactively                                  16,028,198  35%
   + counsel-M-x                                            7,741,106  17%
   + company-complete-selection                             7,638,354  16%
   + self-insert-command                                      612,824   1%
   + evil-normal-state                                         22,472   0%
   + company-complete-common-or-cycle                          12,386   0%
- jsonrpc--process-filter                                   4,365,568   9%
 - jsonrpc-connection-receive                               3,623,648   8%
  - #<compiled 0x43fe8ead>                                  3,563,700   7%
   - apply                                                  3,563,700   7%
    - #<compiled 0x4114edf1>                                3,563,700   7%
     - eglot--hover-info                                    3,459,414   7%
      - mapconcat                                           3,459,414   7%
       - eglot--format-markup                               3,457,279   7%
        - gfm-mode                                          2,963,302   6%
         - run-mode-hooks                                   1,952,578   4%
          - run-hooks                                       1,763,783   3%
           - yas-global-mode-enable-in-buffers              1,649,813   3%
            - yas-minor-mode-on                             1,649,813   3%
             - yas-minor-mode                               1,649,813   3%
              - yas--load-pending-jits                      1,648,629   3%
               - #<compiled 0x4093ca4f>                     1,648,629   3%
                - apply                                     1,648,629   3%
                 - yas--load-directory-1                    1,648,629   3%
                  - yas--load-directory-2                   1,640,413   3%
                   - yas--parse-template                      495,622   1%
                    - yas--calculate-group                    264,668   0%
                     - locate-dominating-file                 264,668   0%
                        abbreviate-file-name                   53,344   0%
                      match-string-no-properties               36,288   0%
                   - insert-file-contents                     392,236   0%
                    - set-auto-coding                         367,660   0%
                     - find-auto-coding                       365,548   0%
                        auto-coding-alist-lookup              177,272   0%
                        auto-coding-regexp-alist-lookup       135,260   0%
                        sgml-xml-auto-coding-function          25,624   0%
                        sgml-html-meta-auto-coding-function        24,576   0%
                      format-decode                            24,576   0%
                   - yas--subdirs                             114,144   0%
                    - directory-files                          80,096   0%
                     - ucs-normalize-hfs-nfd-post-read-conversion        79,040   0%
                      - ucs-normalize-HFS-NFC-region           79,040   0%
                         ucs-normalize-region                  76,928   0%
                    - cl-remove-if                             12,432   0%
                     - apply                                   12,432   0%
                      - cl-remove                              12,432   0%
                         #<compiled 0x448359f1>                12,432   0%
                   - yas-define-snippets                       81,832   0%
                    - yas--define-snippets-1                   73,560   0%
                     - yas--update-template                    65,288   0%
                        yas--add-template                      57,904   0%
                      - yas--update-template-menu               6,336   0%
                         yas--delete-from-keymap                3,176   0%
                     - apply                                    8,272   0%
                        yas--define-snippets-2                  8,272   0%
                      yas--table-get-create                     8,272   0%
                     generate-new-buffer                        2,122   0%
                     yas--load-yas-setup-file                   1,048   0%
                   - #<compiled 0x404c3329>                     1,024   0%
                    - kill-buffer                               1,024   0%
                       tramp-flush-file-function                1,024   0%
                  - load                                        2,048   0%
                   - substitute-env-in-file-name                2,048   0%
                      substitute-env-vars                       2,048   0%
           + smartparens-global-mode-enable-in-buffers         85,930   0%
           + evil-mode-enable-in-buffers                       28,040   0%
          - apply                                             188,795   0%
           - run-hooks                                        188,795   0%
            + readable-mode                                   160,165   0%
            + flyspell-mode                                    17,040   0%
            + bug-reference-mode                               10,366   0%
              visual-line-mode                                    120   0%
            + add-evil-normal-state-entry-hook--markdown-mode            40   0%
            + add-evil-insert-state-entry-hook--markdown-mode            40   0%
         - do-after-load-evaluation                           421,282   0%
          - run-hook-with-args                                402,850   0%
           + eval-after-load-helper                           394,640   0%
           - eval-after-load-helper                             8,210   0%
            + #<lambda 0x310ca9c>                               8,210   0%
         + #<compiled 0x440236c1>                             232,612   0%
         + require                                             39,014   0%
         + markdown-make-header-faces                          20,188   0%
         + defconst                                            16,376   0%
         + byte-code                                           13,508   0%
         + markdown-mode                                       12,388   0%
         + defvar                                              11,320   0%
         + easy-menu-do-define                                  5,280   0%
         + substitute-env-in-file-name                          1,024   0%
        + font-lock-ensure                                    212,505   0%
        + typescript-mode                                      72,678   0%
        + #<compiled 0x447562a9>                                4,256   0%
          generate-new-buffer                                   4,244   0%
          flycheck-handle-change                                2,048   0%
        + markdown-gfm-checkbox-after-change-function           1,102   0%
     - eldoc-message                                          104,286   0%
      - eldoc-minibuffer-message                              104,286   0%
       - apply                                                104,286   0%
        - message                                              97,876   0%
         + redisplay_internal (C function)                     25,936   0%
  + #<compiled 0x4415a231>                                     59,948   0%
 - jsonrpc--json-read                                         219,132   0%
  - json-read                                                 219,132   0%
   - json-read-object                                         219,132   0%
    - json-read                                               186,380   0%
     - json-read-object                                       177,168   0%
      - json-read                                             177,168   0%
         json-read-number                                       3,072   0%
       json-read-number                                         1,024   0%
 - #<compiled 0x44758929>                                     215,790   0%
  + kill-buffer                                               212,622   0%
   generate-new-buffer                                        103,978   0%
+ timer-event-handler                                       2,062,958   4%
+ redisplay_internal (C function)                             646,836   1%
+ direnv--maybe-update-environment                             76,306   0%
+ ...                                                          51,852   0%
+ symbol-overlay-post-command                                  17,516   0%
+ winner-save-old-configurations                                5,192   0%
  list                                                          4,871   0%
joaotavora commented 6 years ago

this seems to have improved the situation

Great. The profile looks saner now. How noticeable would you say the improvement is (time cut in 50%? 25%?).

Anyway, I'm going to turn off logging by default (at least for this server).

terlar commented 6 years ago

Hard to say, now when I keep trying it is hard to tell, since it is a bit inconsistent. Sometimes it felt somewhat useable and then when I retry from scratch it turns out it to have similar issues. Still not useable in this project (which has 8000 js files), the completion makes the keys lag slower than you can type and freezes. But I tried a smaller project and there it was quite quick, not impacting the typing experience. The worst part is the initial completion when it gets the first list since you connected to the eglot server, then it freezes for a few seconds.

But perhaps 25% was the general feeling, I have to do some more investigation, perhaps with most packages disabled, to make the profiling less horrendous.

joaotavora commented 6 years ago

The worst part is the initial completion when it gets the first list since you connected to the eglot server, then it freezes for a few seconds.

Hmmm, the commit I had earlier is supposed to fix exactly these freezes.

most packages disabled, to make the profiling less horrendous.

Yes this would be welcome. A test project where I can witness these effects myself is also useful.

joaotavora commented 6 years ago

So the "snappy company" fix is now in master. Please try it out, but notice that it requires a new jsonrpc.el version. When MELPA updates it in a few hours it should sort this detail automatically.

Tomorrow I will reanalyse the logging-related slowdown and provide a fix to that too (possibly disabling all logging by default).

jojojames commented 6 years ago

@joaotavora

OK, good. Can you tell me which server you are using?

Cquery, I need to try this out with the kotlin-langserver I am playing with too but I'm guessing both would work about the same.

Flymake-mode isn't really connected to completions. More importantly flymake only kicks in when you have stopped typing after a little while.

I agree, I think it kicks in quite often for me though, (at least it seems that way). Not sure.

Indeed, the processing after receiving a lot of diagnostics is non-trivial, so that may explain the delay you see. However I need to see more than an eyeball test. Can you describe or show a controlled experiment? I need

The server/language you are using
The file, supposing it is self-sufficient

cquery, window.c in emacs' codebase.

I just type random characters in any of the functions and notice it.

Alternatively, you can use the profiler

Once, I find some time, I'll try and give better diagnostics (understandably, the above is kindof hand-wavy :)) and create a new thread for this topic.

terlar commented 6 years ago

@joaotavora I can report back that it is working much better now, the speed of the completion is still about the same, but it is not blocking the character input which was the thing that really made it hard to use.

I don't think I got it to load the new branch version properly, must have been the old code. Will double check the load-path next time. Sorry for the inconvenience and thanks for the fix.

joaotavora commented 6 years ago

the speed of the completion is still about the same, but it is not blocking the character input which was the thing that really made it hard to use.

Great. That is precisely the intended effect.

joaotavora commented 6 years ago

I agree, I think it kicks in quite often for me though

You can control how often it kicks in though. See the docstring of flymake-mode.

cquery, window.c in emacs' codebase. I just type random characters in any of the functions and notice it.

Thanks. Don't you need some kind of compilation database?

 Once, I find some time, I'll try and give better diagnostics (understandably, the above is kindof hand-wavy :)) and create a new thread for this topic.

Good idea. Thanks.

jojojames commented 6 years ago

You can control how often it kicks in though. See the docstring of flymake-mode.

Thanks, I'll take a look. Maybe that will be enough.

Thanks. Don't you need some kind of compilation database?

I use

make clean; bear make;

to generate the compilation database.