使用spacemacs打开文件耗时5-10秒左右

安装完spacemacs后,在layers中有如下的layer: (auto-completion :variables auto-completion-enable-snippets-in-popup t) better-defaults emacs-lisp git helm ;; lsp ;; markdown multiple-cursors org ;; (shell :variables ;; shell-default-height 30 ;; shell-default-position 'bottom) ;; spell-checking ;; syntax-checking ;; version-control treemacs

之前开spell-checking和syntax-checking更慢,且编辑的时候会卡住,去掉这两个layer后,有改善,但感觉打开文件的速度还是比较慢,要5-10s,请问要怎么加快呢?是package太多了吗?目前有246个package,都是在安装这几个layer时安装的

这种情况很有可能跟字体有关,可以尝试设置下中英文字体。论坛里有不少帖子解决字体问题,你可以搜索一下。

我在user-config中加入了一些字体方面的配置,但感觉没有什么改善

(defun dotspacemacs/user-config ()
  "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer
configuration.
Put your configuration code here, except for variables that should be set
before packages are loaded."
;;  (global-company-mode t)
  (global-set-key (kbd "C-s") 'swiper)
  (setcdr evil-insert-state-map nil)

  (define-key evil-insert-state-map
    (read-kbd-macro evil-toggle-key) 'evil-emacs-state)

  (define-key evil-insert-state-map [escape] 'evil-normal-state)

    (setq inhibit-compacting-font-caches t)
(add-to-list 'after-make-frame-functions
	     (lambda (new-frame)
	       (select-frame new-frame)
           (set-default-font "-outline-微软雅黑-normal-normal-normal-sans-16----p--iso8859-1")))
  )

打开文件慢,你可以看一下 find-file-hook下面有多少东西。最好是用 profiler 来测试一下

请问要怎么看find-file-hook下的东西呢? 不好意思,刚刚接触spacemacs ,还不太会看

C-h v (describe-variable) 查看 find-file-hooks 里面有什么。

这些hook都是会在打开文件的时候调用的, 例如我的就是这样的:

magit-branch-description-check-buffers
global-magit-file-mode-check-buffers
magit-auto-revert-mode-check-buffers
git-commit-setup-check-buffer
global-atomic-chrome-edit-mode-check-buffers
projectile-find-file-hook-function
auto-revert--global-adopt-current-buffer
auto-revert-find-file-function
recentf-track-opened-file
doom-modeline-update-persp-name
doom-modeline-update-vcs-text
doom-modeline-update-vcs-icon
doom-modeline-update-buffer-file-name
doom-modeline-update-buffer-file-icon
doom-modeline-update-env
evil-mode-check-buffers
global-evil-surround-mode-check-buffers
global-undo-tree-mode-check-buffers
undo-tree-load-history-from-hook
bm-buffer-restore
url-handlers-set-buffer-mode
epa-file-find-file-hook
global-eldoc-mode-check-buffers
global-font-lock-mode-check-buffers
vc-refresh-state
save-place-find-file-hook
which-func-ff-hook

如果这个看不出来是啥的话,打开Emacs,然后M-x运行profiler-start,然后打开一个文件。完成加载之后再M-x运行profiler-report查看CPU占用

1赞

我发现大量的cpu时间都花在了require上,这是在联网获取什么东西吗?