Skip to content

vite build causes OOMs due to spawning deno info with unbounded concurrency. #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jhgg opened this issue Feb 23, 2025 · 3 comments · May be fixed by #61
Open

vite build causes OOMs due to spawning deno info with unbounded concurrency. #50

jhgg opened this issue Feb 23, 2025 · 3 comments · May be fixed by #61

Comments

@jhgg
Copy link

jhgg commented Feb 23, 2025

When using this plugin, we notice that builds OOM, because too many deno info processes are spawned. This causes >8GB of memory pressure on our build machine, which kills the build :(

In addition, build times are significantly slower due to having to call out to info for every dependency. This slows down our build significantly, taking the total vite build time from ~2.43s to 20s on my machine.

@Garciat
Copy link

Garciat commented Mar 4, 2025

I also noticed way slower builds:

With plugin:

➜  deno task build
Task build deno run -A npm:vite build
vite v6.2.0 building for production...
✓ 1650 modules transformed.
dist/index.html                   0.43 kB │ gzip:  0.28 kB
dist/assets/index-D7fEyQzs.css   10.50 kB │ gzip:  2.07 kB
dist/assets/index-CrJfWa1s.js   317.15 kB │ gzip: 96.32 kB
✓ built in 26.81s

Without plugin:

➜  deno task build
Task build deno run -A npm:vite build
vite v6.2.0 building for production...
✓ 1650 modules transformed.
dist/index.html                   0.43 kB │ gzip:  0.28 kB
dist/assets/index-RZhrGdRc.css   10.43 kB │ gzip:  2.04 kB
dist/assets/index-C6cbh9Sm.js   317.19 kB │ gzip: 96.33 kB
✓ built in 1.26s

@Garciat
Copy link

Garciat commented Mar 4, 2025

I found a workaround for my case.

My deno.json file contained the following and I wanted that to be honored by Vite.

  "imports": {
    "src/": "./src/",
    "lib/": "./lib/"
  },

And I found that I can do that with resolve.alias:

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "lib": import.meta.resolve("./lib"),
      "src": import.meta.resolve("./src"),
    },
  },
});

lbsal added a commit to masslbs/deno-vite-plugin that referenced this issue Apr 14, 2025
This fix builds on the insight in denoland#55 but does so by performing the
minimal change required to fix the underlying issue. The reason for this
departure from denoland#55 is due to our project's build failing when executed
using the proof of concept's plugin, presumably due to some unknown
change introduced on part of the proof of concept's extensive revision.

The fix reuses @notcome's lock component and threads said lock through
the codebase to ultimately place it around the `deno info --json ${id}`
calls.
lbsal added a commit to masslbs/deno-vite-plugin that referenced this issue May 7, 2025
This fix builds on the insight in denoland#55 but does so by performing the
minimal change required to fix the underlying issue. The reason for this
departure from denoland#55 is due to our project's build failing when executed
using the proof of concept's plugin, presumably due to some unknown
change introduced on part of the proof of concept's extensive revision.

The fix reuses @notcome's lock component and threads said lock through
the codebase to ultimately place it around the `deno info --json ${id}`
calls.
@lbsal
Copy link

lbsal commented May 26, 2025

For what it's worth:

We've forked this at https://github.com/masslbs/deno-vite-plugin and published the fork so that it can be used by ci: https://www.npmjs.com/package/@masslbs/deno-vite-plugin

Info from the fork's README:

Care has been taken to avoid introducing changes in the final output arrived at by running this version of deno-vite-plugin compared to the upstream version. The result of this fork is that it uses a bounded amount of memory and its execution time is faster after a first run has populated the cache.

This fork:

  • uses a lock to limit external calls to deno info --json
  • improves how the in-memory cache is used by catching more cases
  • implements an on-disk cache, speeding up initial loading considerably

The on-disk cache is only written after a clean exit from vite, or when the server restarts as that is when Rollup's buildEnd phase runs.

Prevent the on-disk cache from being used by setting the environment variable NOCACHE e.g. NOCACHE="1" deno run dev. This can be helpful if debugging any build errors that may/may not have to do with caching.

Logging what the plugin is doing at any point in time can be enabled by providing DEBUG=deno-vite-plugin or DEBUG=*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants