Skip to content

Input .js file size heuristic + heap size check to proactively warn users about likely v8::internal::V8::FatalProcessOutOfMemory failure and how to increase heap size with NODE_OPTIONS="--max-old-space-size=8192" / similar #223

Description

@0xdevalias

While it is documented that heap size can be increased for large bundles, I see a number of people still running into issues where they aren't aware of that or similar; and then thinking it is a bug / crash / memory leak within webcrack itself.

I was thinking that the .js bundle size being processed likely corresponds roughly to heap size required, and so it might be possible to determine some heuristics around what sort of bundle size might need the heap increased with NODE_OPTIONS="--max-old-space-size=8192" or similar.

I believe it's possible to programmatically get the current heap size limit, as well as stats on how much is used, total system memory available, etc:

import v8 from "node:v8";
import os from "node:os";
import process from "node:process";

const mib = bytes => Math.round(bytes / 1024 / 1024);

const heap = v8.getHeapStatistics();
const mem = process.memoryUsage();

console.log({
  // Effective V8 heap ceiling, affected by --max-old-space-size
  heapSizeLimitMiB: mib(heap.heap_size_limit),

  // Current JS heap usage
  usedHeapMiB: mib(heap.used_heap_size),
  totalHeapMiB: mib(heap.total_heap_size),

  // Whole process resident memory, not just JS heap
  rssMiB: mib(mem.rss),

  // System memory
  systemTotalMiB: mib(os.totalmem()),
  systemFreeMiB: mib(os.freemem()),

  // Explicit CLI flags, but note: NODE_OPTIONS flags may not appear here
  execArgv: process.execArgv,

  // Raw env var, if set
  nodeOptions: process.env.NODE_OPTIONS,
});

Using something like that, maybe a warning could be shown at the start of a run if it is believed the process might crash out with a v8::internal::V8::FatalProcessOutOfMemory

It might also be possible to monitor it during the run and give feedback before the fatal error is hit.

See Also

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions