syl20bnr / spacemacs

A community-driven Emacs distribution - The best editor is neither Emacs nor Vim, it's Emacs *and* Vim!
http://spacemacs.org
GNU General Public License v3.0
23.64k stars 4.89k forks source link

Opening python files is very slow #16529

Closed sid-kap closed 1 week ago

sid-kap commented 3 weeks ago

Description :octocat:

Opening python in python-mode files is very slow

Reproduction guide :beetle:

Observed behaviour: :eyes: :broken_heart: It takes like 2-3 seconds for the file to open

Expected behaviour: :heart: :smile: It should open faster

System Info :computer:

Profiler report

  1015  85% - command-execute
  1015  85%  - call-interactively
  1015  85%   - funcall-interactively
  1009  84%    - spacemacs-buffer/return
  1009  84%     - if
  1009  84%      - widget-button-press
  1009  84%       - widget-apply-action
  1009  84%        - widget-apply
  1009  84%         - #<lambda -0x18c06ecd5c426d65>
  1009  84%          - find-file-existing
  1009  84%           - find-file
  1009  84%            - find-file-noselect
  1009  84%             - apply
  1009  84%              - editorconfig--advice-find-file-noselect
  1008  84%               - apply
  1008  84%                - #<compiled -0x25ea928a4de5da0>
  1005  84%                 - find-file-noselect-1
  1003  84%                  - after-find-file
    920  77%                   - normal-mode
    920  77%                    - set-auto-mode
    919  77%                     - set-auto-mode--apply-alist
    918  77%                      - set-auto-mode-0
    892  74%                       - python-mode
    841  70%                        - run-mode-hooks
    497  41%                         - apply
    497  41%                          - run-hooks
    223  18%                           + spacemacs//pyvenv-mode-set-local-virtualenv
    156  13%                           + spacemacs/load-yasnippet
    68   5%                           + #<lambda 0x1ddaee27>
    24   2%                           + spacemacs//python-default
      3   0%                           + bug-reference-prog-mode
      2   0%                             sphinx-doc-mode
      2   0%                           + code-cells-mode
    330  27%                         - hack-local-variables
    329  27%                          - hack-local-variables-apply
    329  27%                           - run-hooks
    329  27%                            - spacemacs//run-local-vars-mode-hook
    329  27%                             - run-hooks
    309  25%                              - spacemacs//python-setup-eldoc
    309  25%                               - if
    309  25%                                - progn
    309  25%                                 - spacemacs//python-setup-anaconda-eldoc
    309  25%                                  + if
    20   1%                              + spacemacs//python-setup-company
      1   0%                          + hack-dir-local-variables
    14   1%                         + run-hooks
    25   2%                        + byte-code
    16   1%                        + do-after-load-evaluation
      1   0%                        + defvar
      1   0%                     + hack-dir-local--get-variables
    83   6%                   + run-hooks
      1   0%                  + insert-file-contents
      1   0%                  + file-truename
      2   0%                 + find-buffer-visiting
      1   0%               + editorconfig-call-get-properties-function
      3   0%      profiler-stop
      2   0%      profiler-start
      1   0%    + evil-previous-line
    124  10% + timer-event-handler
    47   3% + redisplay_internal (C function)
      1   0% + ...
      1   0% + eldoc-schedule-timer
      1   0% + #<compiled 0x2b383d71bc76035>
      1   0% + evil-repeat-pre-hook
sunlin7 commented 2 weeks ago

Does it happened every time or just first time? According your profiler report, the heavy part is initializing the local virtualenv and the anaconda-eldoc, loading the yasnippet. 223 18% + spacemacs//pyvenv-mode-set-local-virtualenv 156 13% + spacemacs/load-yasnippet 309 25% - spacemacs//python-setup-anaconda-eldoc

You can disable one of them to locate the most expensive one.

smile13241324 commented 2 weeks ago

You could also switch to LSP and see if it improves your startup performance. I am working in python projects all the time and did never notice startup delays of more than 1 second which is acceptable for an IDE.

sid-kap commented 1 week ago

Setting python-auto-set-local-pyvenv-virtualenv nil helped a lot, thanks @sunlin7!!

sunlin7 commented 1 week ago

Good :clap: