# 在低内存环境中改进 JS 构建时间（2024年5月）

**URL:** <https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462>\
**Category:** Self-hosting\
**Tags:** server-resources\
**Created:** [2024年五月2日 11:01 UTC](https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462 "2024-05-02T11:01:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2024年五月2日 11:01 UTC](https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462/1 "2024-05-02T11:01:20Z")

</div>

我们的官方安装指南列出了 Discourse 的最低要求：1GB RAM（+2GB 交换空间）。这仍然是可能的，但在过去的几个月里，在具有此规格的服务器上重建 Discourse 变得越来越痛苦。这主要是由于我们 JS 构建工具的变化。

我们刚刚完成了这些调整，这应该会显著改善低内存服务器上的重建时间：

> <https://github.com/discourse/discourse/commit/9db5eafb15688cf0604805fb5b315efca1c712a6>
>
> \- Use 'cheap-source-map' webpack config on low-memory machines
> 
> This results… in worse quality sourcemaps in browser dev tools, but it significantly reduces memory use in our webpack build. In approximate local testing it drops from 1100mb to 590mb. This should make the rebuild process on low-memory machines much faster and less likely to trigger OOM errors.
> 
> In development, and on higher-memory machines, the higher-quality 'source-map' option is maintained.
> 
> \- Disable Webpack's built-in \`minimize\` feature. Embroider already applies Terser after the webpack build is complete. There is no need to double-minimize the output.
> 
> \- Update ember-cli-progress-ci to print to stderr instead of stdout. For some reason, pups (used by discourse\_docker) buffers the stdout of commands and only prints when they are finished. stderr does not have this same limitation, so switching will mean sysadmins can see the progress of the ember build in real-time.
> 
> Given the number of variables it's hard to promise exact numbers. But, in my tests on a DO droplet with 1GB RAM (+2GB swap), this reduced the \`ember build\` portion of a \`./launcher rebuild app\` from ~50 minutes to ~15 minutes.

考虑到变量众多，很难承诺确切的数字。但是，在我使用 1GB RAM（+2GB 交换空间）的 DO 淌器上的测试中，这使得 `./launcher rebuild app` 的 `ember build` 部分从约 45 分钟减少到约 15 分钟。

内存更多的机器也可能获得轻微的速度提升，但提升幅度不大。

如果您在低内存机器上运行 Discourse，请尝试一下，并告诉我们您的使用情况！

---

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [2024年五月2日 11:06 UTC](https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462/2 "2024-05-02T11:06:52Z")

</div>

我敢肯定我不是唯一这么想的人，但这对于自助托管者来说将是一个巨大的帮助，可以降低他们的成本，推动采用，太棒了！！

这是对社区的极好承诺的体现，谢谢！

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [2024年五月2日 11:10 UTC](https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462/3 "2024-05-02T11:10:30Z")

</div>



---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2024年五月2日 15:55 UTC](https://meta.discourse.org/t/improvements-to-js-build-times-in-low-memory-environments-may-2024/306462/4 "2024-05-02T15:55:43Z")

</div>

太棒了！

我刚刚进行了一次测试安装，整个过程，包括创建 Droplet、（自动）DNS 配置、从 Mailgun 获取 SMTP 凭据，以及带有大量插件的重建（以及删除 Droplet），仅用了 23 分钟。这真是太棒了，因为我之前在 8GB Droplet 上运行这个测试，而 1GB 的 Droplet 耗时太长了。

看起来 30 分钟安装再次成为可能了！
