简体   繁体   English

为什么我的 ember-cli 构建时间在 Windows 上如此缓慢?

[英]Why is my ember-cli build time so slow on windows?

Ember-cli is building very slowly with ember server on windows. Ember-cli 在 Windows 上使用ember server构建非常缓慢。

Build successful - 13126ms.

Slowest Trees                  | Total
-------------------------------+----------------
TreeMerger (vendor)            | 3154ms
TreeMerger (stylesAndVendor)   | 2051ms
TreeMerger (appAndDependencies) | 1914ms
StaticCompiler                 | 1791ms

This is in contrast to the same project building in less that 1 second on a linux box.这与在 linux 机器上在不到 1 秒内构建相同的项目形成对比。

There are two big culprits:罪魁祸首有两个:

  1. Real time file system scanning or protection实时文件系统扫描或保护
    • Realtime-protection from Windows Defender (also know as Microsoft Security Essentials in win7)来自 Windows Defender 的实时保护(在 win7 中也称为 Microsoft Security Essentials)
    • Windows Search Indexing Windows 搜索索引
    • Antivirus scanning防病毒扫描
  2. Unused files in your bower_components folder bower_components 文件夹中未使用的文件

Real time Scanning实时扫描

During a build numerous files are generate in the ./tmp folder of the ember project, both the indexer and the realtime-protection make additional reads of each file which adds a significant amount of additional file I/O operations.在构建过程中,在 ember 项目的./tmp文件夹中生成了./tmp文件,索引器和实时保护都会对每个文件进行额外读取,这会增加大量额外的文件 I/O 操作。

The fix is to:解决方法是:

This should get your build time down to a couple seconds.这将使您的构建时间缩短到几秒钟。 Additional speed improvements for Windows are being investigated continuing to be investigated in relation to Broccoli's handling of the build process.正在调查Windows 的其他速度改进,继续调查Broccoli 对构建过程的处理。

Managing unused bower files管理未使用的凉亭文件

Having lots of files in the bower_components is the biggest culprit . bower_components 中大量文件是最大的罪魁祸首

I wrote up a script, clean-ember-cli.js , that deletes everything but ember-cli dependancies, and anything imported in the Brocfile.js .我编写了一个脚本clean-ember-cli.js ,它删除了除 ember-cli 依赖项之外的所有内容,以及在Brocfile.js导入的Brocfile.js I'm getting back to around 5 second build times.我回到了大约 5 秒的构建时间。

Update更新

Reports are that running console as admin also helps. 报告显示,以管理员身份运行控制台也有帮助。

Official recommendation from ember-cli to improve its performance on windows来自 ember-cli 的官方推荐以提高其在 windows 上的性能

Install ember-cli-windows with node using the below command使用以下命令安装带有节点的 ember-cli-windows

npm install -g ember-cli-windows

Run the following command on your project root folder在您的项目根文件夹上运行以下命令

ember-cli-windows

mind one important thing... and I didn`t found out in any forum... if you are working with a laptop and you are not connected with AC, windows may run in low performance mode to keep battery.请注意一件重要的事情...我没有在任何论坛上发现...如果您使用的是笔记本电脑并且没有连接交流电,Windows 可能会在低性能模式下运行以保持电池电量。 This cause ember build proyects 4 times slower这会导致 ember build proyects 慢 4 倍

在以管理员身份运行的命令提示符下使用 ember-cli 1.13.13 为我修复了它

In addition to answers provided above run除了上面提供的答案运行

ember s

in powershell in admin mode.在管理模式的 powershell 中。 This enables symlinks which are not enabled by default in windows.这将启用 Windows 中默认未启用的符号链接。 Having symlinks creates a flatter node_modules folder which results in faster running times.拥有符号链接会创建一个更扁平的 node_modules 文件夹,从而缩短运行时间。

( Source ) 来源

From build 20262 Windows 10 have WSL 2 .从 build 20262 Windows 10 开始有WSL 2 This is Linux on your machine and gives us performance as good as on Linux.这是您机器上的 Linux,它为我们提供了与 Linux 一样好的性能。

Get last Ubuntu from Microsoft store.从 Microsoft 商店获取最后一个 Ubuntu。

Do not use /mnt/ folder for repo because of slow speed, use ~ folder.由于速度慢,请勿使用/mnt/文件夹进行 repo,请使用~文件夹。

Connect with terminal on Ubuntu and clone your repository.在 Ubuntu 上连接终端并克隆您的存储库。

    cd ~
    git clone your-repo

install node version manager and node安装节点版本管理器节点

Install ember-cli and start server.安装 ember-cli 并启动服务器。

    npm install -g ember-cli
    cd ~/your-repo
    npm i
    ember serve

In VSCode install plugin "Remote - WSL" , open your repo and start development.在 VSCode 安装插件“Remote - WSL”中打开你的仓库并开始开发。

With Windows 7 I got a 50% improvement by turning off Encrypting File System (EFS) for the project's /tmp directory.在 Windows 7 中,我通过关闭项目/tmp目录的加密文件系统 (EFS) 获得了 50% 的改进。 (right-click Properties->Advanced->Encrypt contents...) (右键属性->高级->加密内容...)

For later versions of Ember CLI running in admin mode as mentioned here and suggested by D-Go in his answer seems to be the way to go, assuming your company allows this.对于提到在管理模式下运行灰烬CLI的后续版本在这里他的答案和建议的d-围棋似乎是要走的路,假设您的公司允许这样做。

If like me you are using GIT Bash to run Ember you may be interested in how to set it up to automatically run in admin mode here如果你像我一样正在使用GIT的Bash运行灰烬,你可能有兴趣在如何将它设置为在管理模式下自动运行在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM