oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.1k stars 2.76k forks source link

`bun --hot` always leaks memory #11083

Open paperdave opened 5 months ago

paperdave commented 5 months ago

What version of Bun is running?

No response

What platform is your computer?

No response

What steps can reproduce the bug?

import { spawn } from "bun";
import { writeFileSync } from "node:fs";

let i = 0;
function next() {
  i++;
  writeFileSync(
    "hello.mjs",
    `// This is a medium sized testing file
// ${"contents".repeat(100)}
Bun.gc(true);
console.log('RSS in run %s is %d MB', ${i}, process.memoryUsage().rss / 1_000_000);
console.err('[done]');
`,
  );
}

next();

await using runner = spawn({
  cmd: [
    //
    process.execPath,
    "--hot",
    "run",
    "hello.mjs",
  ],
  stdio: ["ignore", "inherit", "pipe"],
  env: {
    ...process.env,
    NO_COLOR: true,
  },
});

for await (const chunk of runner.stderr) {
  if (new TextDecoder().decode(chunk).includes("[done]")) {
    next();
  }
}

What is the expected behavior?

to not leak memory

What do you see instead?

image

Additional information

No response

Jarred-Sumner commented 2 months ago
RSS in run 57454 is 127 MB
RSS in run 57455 is 127 MB
RSS in run 57456 is 127 MB
RSS in run 57457 is 127 MB
RSS in run 57458 is 127 MB
RSS in run 57459 is 127 MB
RSS in run 57460 is 127 MB
RSS in run 57461 is 127 MB
RSS in run 57462 is 127 MB
RSS in run 57463 is 127 MB
RSS in run 57464 is 127 MB
RSS in run 57465 is 127 MB
RSS in run 57466 is 127 MB
RSS in run 57467 is 127 MB
RSS in run 57468 is 127 MB
RSS in run 57469 is 127 MB
RSS in run 57470 is 127 MB
RSS in run 57471 is 127 MB
RSS in run 57472 is 127 MB
RSS in run 57473 is 127 MB
RSS in run 57474 is 127 MB
RSS in run 57475 is 127 MB
RSS in run 57476 is 127 MB
RSS in run 57477 is 127 MB
RSS in run 57478 is 127 MB
RSS in run 57479 is 127 MB
RSS in run 57480 is 127 MB
RSS in run 57481 is 127 MB
RSS in run 57482 is 127 MB
RSS in run 57483 is 127 MB
RSS in run 57484 is 127 MB
RSS in run 57485 is 127 MB
RSS in run 57486 is 127 MB
RSS in run 57487 is 127 MB
RSS in run 57488 is 127 MB
RSS in run 57489 is 127 MB
RSS in run 57490 is 127 MB
RSS in run 57491 is 127 MB
RSS in run 57492 is 127 MB
RSS in run 57493 is 127 MB
RSS in run 57494 is 127 MB
RSS in run 57495 is 127 MB
RSS in run 57496 is 127 MB
RSS in run 57497 is 127 MB
RSS in run 57498 is 127 MB
RSS in run 57499 is 127 MB
RSS in run 57500 is 127 MB
RSS in run 57501 is 127 MB
RSS in run 57502 is 127 MB
RSS in run 57503 is 127 MB
RSS in run 57504 is 127 MB
RSS in run 57505 is 127 MB
RSS in run 57506 is 127 MB
RSS in run 57507 is 127 MB
RSS in run 57508 is 127 MB
RSS in run 57509 is 127 MB
RSS in run 57510 is 127 MB
RSS in run 57511 is 127 MB
RSS in run 57512 is 127 MB

62% less memory leaked as of Bun v1.1.27

paperdave commented 1 month ago

this code also shows a bundler regression re:using but i believe we have issue for that open