热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

mongoconfigshard启动不了_优化ohmyzsh启动速度

前言终于忍受不了越来越慢的zsh启动速度,优化了一下zsh的启动速度。正文环境iTerm23.3.11zsh5.8ohmyzsh(好像没版本号commit5ffc0d
0022770bd2642f7a969d325f465706d7.png

前言

终于忍受不了越来越慢的 zsh 启动速度,优化了一下 zsh 的启动速度。

正文

环境

  • iTerm2 3.3.11
  • zsh 5.8
  • oh my zsh(好像没版本号 commit 5ffc0d036c587741fd25092e7809dad2b00b3677)

初始配置

.zshrc 配置文件如下:

export ZSH=/Users/woodenrobot/.oh-my-zshZSH_THEME="ys"plugins=(sudozzsh_reloadsafe-pasteextracthistory-substring-searchcolored-man-pagesgithistorytmux# 第三方插件zsh-autosuggestionszsh-syntax-highlighting
)source $ZSH/oh-my-zsh.sh# User configuration# Bind key
bindkey '^P' history-substring-search-up
bindkey '^N' history-substring-search-down# 语言配置
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"# pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"# nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm# virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh

其中 zsh-syntax-highlightingzsh-autosuggestions 是通过下列方式安装:

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

通过配置文件可以看出,我安装了几个 oh my zsh 自带的插件以及 pyenvnvmvirtualenvwrapper,安装插件以及其他程序的启动脚本是需要耗费时间的,测试一下 此时 zsh 的启动速度。

$ time zsh -i -c exit

测了三次启动时间如下:

1.54 real 0.78 user 0.73 sys1.55 real 0.80 user 0.72 sys1.83 real 0.83 user 0.80 sys

优化

为了提高启动速度,先把 pyenvnvmvirtualenvwrapper程序改为 lazyload,也就是不在 zsh 启动时就启动只在使用它们的时候启动。

nvm 优化

使用 zsh-nvm 插件实现 nvm 的 lazyload。

  • 下载插件:

$ git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm

  • 然后在 .zshrc 文件中开启插件

plugins=(...zsh-nvm
)

  • 删除 .zshrc 原有的 nvm 启动部分并开启 zsh-nvm 的 lazyload,加入:

# zsh-nvm lazy load
export NVM_LAZY_LOAD=true

pyenv 优化

  • 下载插件:

$ git clone https://github.com/davidparsson/zsh-pyenv-lazy.git ~/.oh-my-zsh/custom/plugins/pyenv-lazy

  • 然后在 .zshrc 文件中开启插件

plugins=(...pyenv-lazy
)

  • 删除 .zshrc 原有的 pyenv 启动部分

virtualenvwrapper 优化

  • 删除原有的 virtualenvwrapper 启动部分;
  • 使用下列 lazyload:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh

完整配置

export ZSH=/Users/woodenrobot/.oh-my-zshZSH_THEME="ys"plugins=(sudozzsh_reloadsafe-pasteextracthistory-substring-searchcolored-man-pagesgithistorytmux# 第三方插件zsh-autosuggestionszsh-syntax-highlightingpyenv-lazyzsh-nvm
)source $ZSH/oh-my-zsh.sh# User configuration# Bind key
bindkey '^P' history-substring-search-up
bindkey '^N' history-substring-search-down# 语言配置
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"# virtualenvwrapper lazy load
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh# zsh-nvm lazy load
export NVM_LAZY_LOAD=true

优化完了测试一下现在的启动速度,老规矩测三次:

0.30 real 0.16 user 0.11 sys0.26 real 0.14 user 0.10 sys0.28 real 0.15 user 0.11 sys

效果感人!!!效果感人!!!效果感人!!!

歪门邪道

zsh 启动速度上来了但是新建一个 iTerm2 tab 好像还是有点慢做不到秒开。网上看到一个不知道什么原理的设置:

进入 iTerm2 的偏好设置里,在 Profiles 里编辑你的配置,在配置右侧的 General 选项卡里,Command 里选择为 Command,然后里边写入 /usr/bin/login -pfq xxx 其中 xxx 是你的用户名。

按照这个配置好,感觉是有那么一点点更快了(更慢了)?总之在我这里改动带来的体验并没有那么大,大家有兴趣可以去试试。

参考

  1. GitHub - lukechilds/zsh-nvm: Zsh plugin for installing, updating and loading nvm
  2. GitHub - davidparsson/zsh-pyenv-lazy: A zsh plugin for lazy loading of pyenv
  3. Installation — virtualenvwrapper 5.0.1.dev2 documentation
  4. iTerm 2、Terminal 启动加速
  5. 让 iTrem 2 + zsh 启动不再等待! | 落格博客zsh-users/zsh-autosuggestions让 iTrem 2 + zsh 启动不再等待! | 落格博客



推荐阅读
author-avatar
mobiledu2502920327
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有