kostafey / ejc-sql

Emacs SQL client uses Clojure JDBC.
279 stars 29 forks source link

delete backwards is slow #131

Closed stardiviner closed 4 years ago

stardiviner commented 4 years ago

I can feel the slow suspend when I delete backwards in SQL like this (the bar | represents the point):

CREATE VIEW vw_cite| AS SELECT * FROM cities WHERE popullar;

I did an Emacs profiler profiling. Here is the results: Memory result

+ command-execute                                                         26,963,904  59%
- timer-event-handler                                                     15,567,367  34%
 - apply                                                                  15,562,671  34%
  - ac-update-greedy                                                      15,458,895  34%
   - ac-update                                                            15,405,871  34%
    - ac-candidates                                                       12,038,427  26%
     - ac-candidates-1                                                    12,014,667  26%
      - ejc-tables-candidates                                              6,433,836  14%
       - ejc-get-tables-candidates                                         6,402,938  14%
        - clomacs-ensure-nrepl-run                                         6,402,938  14%
         - apply                                                           6,402,938  14%
          - #<compiled 0x13233c7fc92c212f>                                 6,344,594  14%
           - nrepl-sync-request:eval                                       5,948,050  13%
            - nrepl-send-sync-request                                      5,946,994  13%
             - accept-process-output                                       5,630,332  12%
              - nrepl-client-filter                                        5,630,332  12%
               - nrepl-bdecode                                             5,567,828  12%
                - fundamental-mode                                         5,301,292  11%
                 - run-mode-hooks                                          5,301,292  11%
                  - run-hooks                                              5,301,292  11%
                   - doom-modeline-update-buffer-file-icon                 5,292,844  11%
                    + all-the-icons-icon-for-buffer                        5,276,552  11%
                    + format-mode-line                                           736   0%
                   + global-aggressive-indent-mode-enable-in-buffers           4,224   0%
                   + global-hl-todo-mode-enable-in-buffers                     1,056   0%
                     diredfl-global-mode-enable-in-buffers                     1,056   0%
                + nrepl--bdecode-message                                     266,536   0%
               + nrepl--dispatch-response                                     61,448   0%
             + nrepl-send-request                                            214,062   0%
             + nrepl-dict-get                                                  1,056   0%
           + clomacs-format-arg                                              231,033   0%
           + clomacs-get-result                                              132,024   0%
           + clomacs-get-connection                                            8,272   0%
       + ejc-get-sql-boundaries-at-point                                      20,658   0%
         apply                                                                 9,184   0%
       + ejc-buffer-connected-p                                                1,056   0%
      - ejc-get-keywords                                                   1,546,830   3%
       - ejc-get-keywords-inner                                            1,403,078   3%
        - clomacs-ensure-nrepl-run                                         1,403,078   3%
         + apply                                                           1,403,078   3%
         mapcar                                                              122,760   0%
       + ejc-buffer-connected-p                                                4,136   0%
      + ejc-colomns-candidates                                             1,461,714   3%
      + ejc-packages-candidates                                              951,583   2%
      + ejc-views-candidates                                                 795,488   1%
      + ejc-owners-candidates                                                776,416   1%
      + ejc-get-ansi-sql-words                                                27,680   0%
      + ac-yasnippet-candidates                                                2,112   0%
    - ac-menu-create                                                       3,366,388   7%
     - popup-create                                                        3,365,332   7%
      - apply                                                              3,365,332   7%
       - #<compiled -0xa509326582b8a7b>                                    3,338,444   7%
        - posn-at-point                                                    1,363,704   3%
         - eval                                                            1,363,704   3%
          + doom-modeline-format--org-src                                    646,532   1%
            doom-modeline-segment--buffer-encoding                           180,292   0%
          + doom-modeline-segment--major-mode                                 92,952   0%
          + doom-modeline-segment--buffer-position                            89,480   0%
            doom-modeline-segment--buffer-info-simple                         46,096   0%
            doom-modeline-segment--debug                                      10,240   0%
            doom-modeline-segment--modals                                      7,232   0%
            doom-modeline-segment--checker                                     6,176   0%
            doom-modeline-segment--input-method                                3,168   0%
        - popup-vertical-motion                                              307,444   0%
         - vertical-motion                                                   224,004   0%
          - jit-lock-function                                                224,004   0%
           + jit-lock-fontify-now                                            219,868   0%
          beginning-of-visual-line                                            86,400   0%
          end-of-visual-line                                                  86,400   0%
         doom-modeline-update-buffer-file-name                                 2,072   0%
    + ac-update-candidates                                                     1,056   0%
   - ac-start                                                                 53,024   0%
    - ac-cleanup                                                              48,888   0%
     - ac-menu-delete                                                         48,888   0%
      - popup-delete                                                          47,832   0%
       + apply                                                                47,832   0%
  + aggressive-indent--indent-if-changed                                      79,728   0%
  + #<compiled 0x14f311354049fa07>                                            22,512   0%
  + blink-cursor-start                                                         1,536   0%
 + timer-activate-when-idle                                                    2,112   0%
 + timer-activate                                                              1,464   0%
 + timer-inc-time                                                                856   0%
- redisplay_internal (C function)                                          1,931,079   4%
 - eval                                                                      979,217   2%
  + doom-modeline-format--org-src                                            201,648   0%
  + doom-modeline-format--main                                               193,872   0%
  + doom-modeline-segment--remote-host                                       105,217   0%
    doom-modeline-segment--buffer-encoding                                    85,656   0%
  + doom-modeline-segment--workspace-name                                     66,320   0%
  + doom-modeline-segment--buffer-position                                    53,024   0%
  + doom-modeline-segment--major-mode                                         51,672   0%
  + doom-modeline-segment--buffer-info                                        29,808   0%
    doom-modeline-segment--buffer-info-simple                                 11,256   0%
    doom-modeline-segment--modals                                              6,136   0%
    doom-modeline-segment--checker                                             5,080   0%
    doom-modeline-segment--debug                                               3,088   0%
    doom-modeline-segment--input-method                                        2,112   0%
 + jit-lock-function                                                         886,922   1%
 + doom-modeline-refresh-bars                                                 40,268   0%
 + eaf-monitor-configuration-change                                           13,944   0%
 + mode-line-default-help-echo                                                 1,056   0%
 + #<compiled 0x68f69ae223c8500>                                               1,056   0%
 + eaf-monitor-window-size-change                                                432   0%
- ac-handle-post-command                                                     248,197   0%
 - ac-start                                                                  248,197   0%
  - ac-prefix                                                                223,496   0%
   - ac-prefix-default                                                       221,464   0%
    - ac-prefix-symbol                                                       189,736   0%
     - bounds-of-thing-at-point                                              184,544   0%
      - #<compiled 0xb4478641b5df7>                                          163,864   0%
       - forward-thing                                                       163,864   0%
          forward-symbol                                                      13,312   0%
  + ac-stop-word-p                                                            15,373   0%
  - ac-set-timer                                                               1,056   0%
   - run-with-idle-timer                                                       1,056   0%
    - timer-set-idle-time                                                      1,056   0%
       timer--time-setter                                                      1,056   0%
+ nrepl-client-filter                                                        149,392   0%
+ flyspell-post-command-hook                                                  70,728   0%
+ ...                                                                         33,478   0%
+ ac-handle-pre-command                                                       15,360   0%
+ url-http-generic-filter                                                     11,472   0%
  xselect-convert-to-targets                                                   3,168   0%
+ xselect-convert-to-string                                                    3,104   0%
+ jit-lock--antiblink-post-command                                             2,112   0%
+ global-magit-file-mode-check-buffers                                         2,112   0%
+ global-company-mode-check-buffers                                            2,112   0%
+ eldoc-schedule-timer                                                         1,128   0%
+ #<lambda 0x862c11a4d24e681>                                                  1,024   0%

CPU result

- timer-event-handler                                                                 471  46%
 - apply                                                                              470  45%
  - ac-update-greedy                                                                  458  44%
   - ac-update                                                                        455  44%
    - ac-candidates                                                                   361  35%
     - ac-candidates-1                                                                360  35%
      - ejc-packages-candidates                                                        90   8%
       - ejc-get-packages-candidates                                                   54   5%
        - clomacs-ensure-nrepl-run                                                     54   5%
         - apply                                                                       54   5%
          - #<compiled 0x13233c7fc92c212f>                                             53   5%
           - nrepl-sync-request:eval                                                   51   4%
            - nrepl-send-sync-request                                                  51   4%
             - accept-process-output                                                   43   4%
              - nrepl-client-filter                                                    41   4%
               - nrepl-bdecode                                                         40   3%
                - fundamental-mode                                                     40   3%
                 - run-mode-hooks                                                      40   3%
                  - run-hooks                                                          40   3%
                   - doom-modeline-update-buffer-file-icon                             38   3%
                    - all-the-icons-icon-for-buffer                                    36   3%
                     - all-the-icons--icon-info-for-buffer                             36   3%
                      - all-the-icons-icon-for-mode                                    36   3%
                       - #<compiled 0xf395d17037cc8d3>                                 36   3%
                        - run-at-time                                                  36   3%
                         - timer-activate                                              35   3%
                          - timer--activate                                            35   3%
                             timer--time-less-p                                        33   3%
                           timer-duration                                               1   0%
                    - format-mode-line                                                  2   0%
                     - apply                                                            2   0%
                        ad-Advice-format-mode-line                                      2   0%
                   - global-font-lock-mode-enable-in-buffers                            1   0%
                      turn-on-font-lock-if-desired                                      1   0%
                   - global-prettify-symbols-mode-enable-in-buffers                     1   0%
                      turn-on-prettify-symbols-mode                                     1   0%
              - timer-event-handler                                                     2   0%
               - apply                                                                  2   0%
                - aggressive-indent--indent-if-changed                                  2   0%
                 - aggressive-indent--proccess-changed-list-and-indent                  2   0%
                  - run-hook-wrapped                                                    1   0%
                   - eval                                                               1   0%
                    - let                                                               1   0%
                       syntax-ppss                                                      1   0%
                  - apply                                                               1   0%
                   - aggressive-indent--softly-indent-region-and-on                     1   0%
                    - aggressive-indent-indent-region-and-on                            1   0%
                     - indent-region                                                    1   0%
                      - indent-region-line-by-line                                      1   0%
                       + indent-according-to-mode                                       1   0%
           - clomacs-format-arg                                                         2   0%
            - clomacs-alist-to-map                                                      2   0%
             - cl-reduce                                                                2   0%
              - #<compiled -0x57983ad82df7a2d>                                          2   0%
               - clomacs-format-arg                                                     2   0%
                  clomacs-add-quotes                                                    2   0%
       - ejc-get-sql-boundaries-at-point                                               35   3%
        - ejc-get-border-bottom                                                        19   1%
         - end-of-buffer                                                               19   1%
          - push-mark                                                                  19   1%
           - apply                                                                     19   1%
              helm--advice-push-mark                                                   19   1%
        - ejc-get-border-top                                                           16   1%
         - beginning-of-buffer                                                         16   1%
          - push-mark                                                                  16   1%
           - apply                                                                     16   1%
              helm--advice-push-mark                                                   16   1%
         apply                                                                          1   0%
      - ejc-colomns-candidates                                                         84   8%
       - ejc-get-colomns-candidates                                                    44   4%
        - clomacs-ensure-nrepl-run                                                     44   4%
         - apply                                                                       44   4%
          - #<compiled 0x13233c7fc92c212f>                                             44   4%
           - nrepl-sync-request:eval                                                   43   4%
            - nrepl-send-sync-request                                                  42   4%
             - accept-process-output                                                   32   3%
              - timer-event-handler                                                    19   1%
               - apply                                                                 19   1%
                - jit-lock-deferred-fontify                                            19   1%
                 - redisplay                                                           19   1%
                  - redisplay_internal (C function)                                     3   0%
                   - eval                                                               3   0%
                    - doom-modeline-format--main                                        2   0%
                     - doom-modeline--font-width                                        2   0%
                      - face-all-attributes                                             2   0%
                       - mapcar                                                         2   0%
                        + #<compiled 0xd636a4ecc63cf87>                                 2   0%
              + nrepl-client-filter                                                    13   1%
             + nrepl-send-request                                                       1   0%
           + clomacs-format-arg                                                         1   0%
       - ejc-get-sql-boundaries-at-point                                               39   3%
        - ejc-get-border-bottom                                                        24   2%
         - end-of-buffer                                                               24   2%
          - push-mark                                                                  23   2%
           - apply                                                                     23   2%
              helm--advice-push-mark                                                   23   2%
        - ejc-get-border-top                                                           15   1%
         - beginning-of-buffer                                                         15   1%
          - push-mark                                                                  15   1%
           - apply                                                                     15   1%
              helm--advice-push-mark                                                   15   1%
       - ejc-buffer-connected-p                                                         1   0%
        + clomacs-get-connection                                                        1   0%
      - ejc-views-candidates                                                           58   5%
       - ejc-get-sql-boundaries-at-point                                               36   3%
        - ejc-get-border-bottom                                                        21   2%
         - end-of-buffer                                                               21   2%
          - push-mark                                                                  21   2%
           - apply                                                                     21   2%
              helm--advice-push-mark                                                   21   2%
        - ejc-get-border-top                                                           15   1%
         - beginning-of-buffer                                                         15   1%
          + push-mark                                                                  15   1%
       - ejc-get-views-candidates                                                      22   2%
        - clomacs-ensure-nrepl-run                                                     22   2%
         - apply                                                                       22   2%
          - #<compiled 0x13233c7fc92c212f>                                             22   2%
           - nrepl-sync-request:eval                                                   21   2%
            - nrepl-send-sync-request                                                  21   2%
             - accept-process-output                                                   12   1%
              - nrepl-client-filter                                                    10   0%
               - nrepl-bdecode                                                          8   0%
                - fundamental-mode                                                      5   0%
                 - run-mode-hooks                                                       4   0%
                  - run-hooks                                                           4   0%
                   + doom-modeline-update-buffer-file-icon                              4   0%
                 + kill-all-local-variables                                             1   0%
                + nrepl--bdecode-message                                                3   0%
               + run-hook-with-args                                                     1   0%
              + url-http-generic-filter                                                 1   0%
             + nrepl-dict-get                                                           1   0%
           + clomacs-format-arg                                                         1   0%
      - ejc-owners-candidates                                                          53   5%
       - ejc-get-sql-boundaries-at-point                                               32   3%
        - ejc-get-border-bottom                                                        19   1%
         - end-of-buffer                                                               19   1%
          - push-mark                                                                  19   1%
           - apply                                                                     19   1%
              helm--advice-push-mark                                                   19   1%
        - ejc-get-border-top                                                           13   1%
         - beginning-of-buffer                                                         13   1%
          - push-mark                                                                  13   1%
           + apply                                                                     13   1%
       + ejc-get-owners-candidates                                                     21   2%
      + ejc-tables-candidates                                                          51   4%
      + ejc-get-keywords                                                               21   2%
      + ac-yasnippet-candidates                                                         2   0%
    - ac-menu-create                                                                   94   9%
     - popup-create                                                                    94   9%
      - apply                                                                          94   9%
       - #<compiled -0xa509326582b8a7b>                                                94   9%
        - posn-at-point                                                                21   2%
         - eval                                                                        21   2%
          - doom-modeline-format--org-src                                              15   1%
           - doom-modeline--font-width                                                 12   1%
            - face-all-attributes                                                      12   1%
             - mapcar                                                                  12   1%
              - #<compiled 0xd636a4ecc63cf87>                                          12   1%
                 face-attribute                                                        12   1%
           + format-mode-line                                                           2   0%
            doom-modeline-segment--buffer-info-simple                                   1   0%
            doom-modeline-segment--checker                                              1   0%
            doom-modeline-segment--buffer-encoding                                      1   0%
          + doom-modeline-segment--buffer-position                                      1   0%
          popup-vertical-motion                                                         4   0%
          beginning-of-visual-line                                                      4   0%
          end-of-visual-line                                                            4   0%
   + ac-start                                                                           3   0%
    #<compiled 0xb8a7af4ffdee9>                                                         5   0%
  + #<lambda 0x14ab2212efab874>                                                         4   0%
  + #<compiled 0x14f311354049fa07>                                                      1   0%
  + aggressive-indent--indent-if-changed                                                1   0%
 + timer-inc-time                                                                       1   0%
- command-execute                                                                     455  44%
 - call-interactively                                                                 454  44%
  - funcall-interactively                                                             454  44%
   + counsel-M-x                                                                      448  43%
   + org-edit-special                                                                   3   0%
   + org-edit-src-exit                                                                  2   0%
   - self-insert-command                                                                1   0%
    - jit-lock-after-change                                                             1   0%
       run-hook-with-args                                                               1   0%
- ...                                                                                  50   4%
   Automatic GC                                                                        49   4%
 + org-entry-get-with-inheritance                                                       1   0%
- redisplay_internal (C function)                                                      34   3%
 - eval                                                                                23   2%
  + doom-modeline-format--org-src                                                      11   1%
  + doom-modeline-format--main                                                          9   0%
  + doom-modeline-segment--buffer-position                                              1   0%
 + jit-lock-function                                                                    7   0%
 + #<compiled 0x68f69ae223c8500>                                                        2   0%
 + doom-modeline-refresh-bars                                                           2   0%
- ac-handle-post-command                                                                5   0%
 - ac-start                                                                             5   0%
  - ac-prefix                                                                           5   0%
   - ac-prefix-default                                                                  5   0%
    - ac-prefix-symbol                                                                  5   0%
     - bounds-of-thing-at-point                                                         3   0%
      - #<compiled 0xb4478641b5df7>                                                     2   0%
       - forward-thing                                                                  2   0%
          forward-symbol                                                                1   0%
- ac-handle-pre-command                                                                 2   0%
 - ac-cleanup                                                                           2   0%
  - ac-remove-quick-help                                                                2   0%
     ac-quick-help-use-pos-tip-p                                                        2   0%
- #<compiled 0x86881d63c055e44>                                                         2   0%
   apply                                                                                2   0%
  global-atomic-chrome-edit-mode-check-buffers                                          1   0%
+ nrepl-client-filter                                                                   1   0%
  jit-lock--antiblink-post-command                                                      1   0%
kostafey commented 4 years ago

The only CPU consumption is related here. Ok, here is a reason for this suspending:

- ac-update-greedy                                                                  458  44%

It's weird. Autocompletion should not be required when you deleting characters. I can't reproduce it. Ok, once again, what do you actually do? Do you only press the Backspace button when point (cursor) is located in this position? What is your buffer major-mode? Is it sql-mode or org-mode?

CREATE VIEW vw_cite| AS SELECT * FROM cities WHERE popullar;
stardiviner commented 4 years ago

what do you actually do? Do you only press the Backspace button when point (cursor) is located in this position? What is your buffer major-mode? Is it sql-mode or org-mode?

Yes, I only pressed the Backspace button, and in sql-mode instead of org-mode.

After your hint, I assume this is not ejc-sql mechanism, so I checked out my auto-complete config. After removed some auto trigger completion configs. The problem is gone.

Sorry for the disturb, I should have a deep thinking of this problem.