web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.71k stars 559 forks source link

Memory leak when using `@rspack/core` API #3169

Open Nikaple opened 1 year ago

Nikaple commented 1 year ago

System Info

  System:
    OS: Linux
    CPU: (16) x64 Intel(R) Xeon(R) Platinum 8255C CPU @ 2.50GHz
    Memory: 19.11 GB / 31.10 GB
    Container: Yes
    Shell: 5.0.2 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  npmPackages:
    @rspack/cli: latest => 0.1.10 
    @rspack/core: ^0.1.10 => 0.1.10 

Details

screenshot

With webpack

screenshot-webpack

Reproduce link

No response

Reproduce Steps

  1. Create a project npm create rspack@latest
  2. Create a script to compile consecutively with @rspack/core
  3. Run the script to get memory leak

Script content:

const { rspack } = require('@rspack/core')
const config = require('./rspack.config')

function compile() {
    const compiler = rspack(config);
    return new Promise((resolve, reject) => {
        compiler.run((err, stat) => {
            if (err) {
                return reject(err)
            }
            return resolve(stat)
        })
    })
}

async function main() {
    await compile();

    setTimeout(() => {
        const memory = process.memoryUsage();
        console.log(`Total memory used: ${Math.round(memory.rss / 1024 / 1024)} MB`)
        main()
    }, 1000);
}

main().catch(console.error)
Boshen commented 1 year ago

Confirmed. How did you discover this? We don't normally import it as a package 🤔

Nikaple commented 1 year ago

I am currently in the process of migrating a complex build tool that is based on webpack. The tool has the ability to compile multiple projects simultaneously, utilizing webpack's core API. However, when attempting to migrate it to rspack, I encountered a persistent issue of the process being killed due to an OOM error.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

pratyushseq commented 9 months ago

bump!

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

Nikaple commented 6 months ago

bump

h-a-n-a commented 6 months ago

@Nikaple I believe this issue has been mitigated:

image

But there's still some leaking problem with the Compiler and Compilation. It's under our investigation.

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

h-a-n-a commented 4 months ago

bump

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

ahqsoftwares commented 1 week ago

Image

The image says rsbuild, but it seems to be related to rspack itself

This happens with the following config

import { defineConfig } from "@rsbuild/core";
import { pluginSvgr } from "@rsbuild/plugin-svgr";
import { pluginBabel } from "@rsbuild/plugin-babel";
import { pluginReact } from "@rsbuild/plugin-react";

export default defineConfig({
  plugins: [
    pluginReact(),
    pluginBabel({
      include: /\.(?:jsx|tsx)$/,
      babelLoaderOptions(opts) {
        opts.plugins?.unshift("babel-plugin-react-compiler");
      },
    }),
    pluginSvgr(),
  ],
  html: {
    template: "./index.html",
  },
  source: {
    entry: {
      index: "./src/index.tsx",
    },
    alias: {
      "@": "./src",
      "@lib": "./src/app/resources",
      "@/*": "./src/*",
    },
  },
  output: {
    distPath: {
      root: "build",
    },
    minify: {
      css: true,
      js: true,
    },
  },
  dev: {
    progressBar: true,
    hmr: true,
    watchFiles: {
      paths: ["./index.html", "./src/**/*"],
    },
  },
  server: {
    port: 3000,
    strictPort: true,
  },
});