Comments (13)
经过测试,这种方法确实有效,大概能缩短~20%的启动时间。测试环境:
macOS Majove, GNU Emacs 26.1
Ubuntu 18.04,GNU Emacs 27.0.50.
究其原因,应该是package 包初始化之后会加载所有的安装包路径,而lisp
目录在相对靠后的位置,这样每次加载配置文件会花时间找路径。这也让我想到了另外一种解决方案,就是把lisp
的路径放到最前面,理论上也会缩短加载的时间,而且改动更小。我在 mscOS 和 Linux 上测试和chenbin 的方法差不多,但不太清楚 Windows 上的情况。
你能帮忙在 Windows 上对比下两种方法吗?把上述代码换成下面即可,调用的地方仍然用require
。
;; Load path
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
(add-to-list 'load-path (expand-file-name "site-lisp" user-emacs-directory))
(defadvice package-initialize (after my-init-load-path activate)
"Reset `load-path'."
(cl-pushnew (expand-file-name "lisp" user-emacs-directory) load-path)
(cl-pushnew (expand-file-name "site-lisp" user-emacs-directory) load-path))
我先commit这种方法。如果 Windows 上相差很大,我再 reopen。我相信这种方法也能极大改善启动时间。
BTW: lisp
和 site-lisp
还是需要加入load-path
,对于查找文件和跳转等还是有用的。比如放到init-const
上直接C-x C-f
是可以直接打开~/.emacs.d/lisp/init-const.el
的。如果没有加入到load-path
,这种操作是无效的。所以如果使用第一种方法也必须启动结束之后再更新。这样实现就不优雅了。
from .emacs.d.
谢谢你的建议!
因为我大多在 Linux 和 macOS 上开发,启动时间已经控制在2s 以内,没有注意到会有这么明显的差别。Windows 确实启动非常慢,所以我一般都打开不会关闭。
这个方案我需要时间测试评估下。Thanks again!
from .emacs.d.
wow, 似乎你的方案比宏还要快!
测试环境: Windows 10 1803 Emacs 26.1
宏 | 直接添加load-path |
新优化方案 | |
---|---|---|---|
emacs-init-time |
8.8s | 12.9s | 8.1s |
benchmark-init |
23241ms | 26161ms | 20793ms |
这可以说是相当惊喜了, 我猜测宏版本比较慢的原因是我没有进行字节码编译 (一般我也不会直接编译 init.el
, 不然实在是太不方便了. ), 反复调用了file-truename
这个函数吃了亏. 我这个宏还是直接从doom哪里提取出来的而不是直接抄的陈斌的, 陈斌的那个就算字节码编译完也不会从这里有优化, 他的comma点错了地方.
无论如何, 谢谢你所做的工作! 另外佩服你的机智 😄
from .emacs.d.
Cool!!! Windows 版本 Emacs 读取文件效率确实不好,毕竟是 msys 编译的。我刚才也简单测试了下,我的Windows环境里大概能缩短~30%的时间。 看起来这是个有效且简洁的solution。也非常感谢你提出的建议,才能想到这样的解决方案。 Thanks! 😄
from .emacs.d.
重构了下,有时间请帮忙Windows 上测试下。注意,这里只能使用push
而不是cl-pushnew
.
(defun update-load-path (&rest _)
"Update `load-path'."
(push (expand-file-name "site-lisp" user-emacs-directory) load-path)
(push (expand-file-name "lisp" user-emacs-directory) load-path))
;; Optimize: Force "lisp"" and "site-lisp" at the head to reduce the startup time.
(advice-add #'package-initialize :after #'update-load-path)
(update-load-path)
from .emacs.d.
Why advice? could I just call update-load-path
before package-initialize
?
from .emacs.d.
谢谢, 两者基本上没有太大的区别. 不用cl-pushnew
的原因是push
的代码会比较简单一些吗?
我之前从未注意到file-truename
的性能问题, 被你提醒后发现它是一个elisp函数, 而expand-file-name
是C函数. 看来宏的问题的确是出在file-truename
这里了.
另外, 我发现如果用use-pacakge
指定:load-path
关键字, use-package
会自作聪明的也把那个path自己push
到load-path
的顶端. 可能用宏比较适合我这种用其他包比较多的人, Thanks!
from .emacs.d.
Why advice? could I just call
update-load-path
beforepackage-initialize
?
update-load-path
needs to be called after package-initialize
. However, package-initialize
was fired up in init-package.el
in his config. So he need Emacs can require init-package.el
first.
from .emacs.d.
不用 cl-pushnew 的原因是 push 的代码会比较简单一些吗?
刚启动时cl-pushnew还没有定义,而且也要复杂一些。 为保持统一改用了push。
from .emacs.d.
@redguardtoo @cireu has explained above. I need to load some config files in ~/.emacs.d/lisp/
first, and keep lisp directory at the head of load-path to speedup after package-iniitialize
.
from .emacs.d.
place (package-initalize)
at the begining of init.el
, update-load-path
is placed at next line, then you don't need advice.
from .emacs.d.
@redguardtoo Right! But in 27, package-initalize
call is unnecessary, I am not very sure the new behaviors. advice
is the safer way, but I will do more testing on 27. Thanks.
from .emacs.d.
Good point.
from .emacs.d.
Related Issues (20)
- [Feature Request] FYI on hl-todos HOT 2
- [Bug] Blank screen on fresh install HOT 7
- [Bug] Find File is very slow HOT 7
- Is dotfiles a dependency of Centaur Emacs?
- Installation process isn't working [Bug] HOT 1
- Installation error [Question] HOT 7
- [Bug] nerd-icons-octicon: Unable to find icon with name ‘key’ in icon set ‘octicon’
- [Bug] Table text cannot be centered, vertical bars cannot be aligned HOT 1
- Supports the opening of large files HOT 12
- Nerd-icon.el url: raw.githubusercontent [Bug] HOT 4
- [Bug] the window size is always maximized at startup HOT 2
- [Feature Request] Maybe 'init-package' should before 'init-custom' HOT 1
- [Feature Request] How could I config PYIM input method with pyim-wbdict? HOT 1
- [Feature Request] How to install package from git, when package is not in melpa HOT 3
- Buffer visualization HOT 2
- 请问怎么关闭透明背景 , 或者调整透明度? HOT 2
- 每次打开文件都提示: Warning (emacs): ‘:events-buffer-scrollback-size’ deprecated. Use ‘events-buffer-config’. HOT 8
- 使用默认主题时, corfu 补全弹出框中选中的高亮行与其它行几乎无法区分 HOT 1
- 怎么打开 flymake 的实时错误检查? HOT 2
- [Bug] my-dashboard-insert-copyright: Symbol’s value as variable is void: dashboard-set-footer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from .emacs.d.