Skip to content

V8's memory leak of Intl.DateTimeFormat causes Deno to use 5G of RAM #10721

@ferk6a

Description

@ferk6a

Hello. So, I was testing Deno 1.9.2 with a workload that involves Temporal and a Postgres database. I noticed that after a few minutes, the 2GB VPS just ran out of memory after some batches of processing. I did the following:

  1. Tried to profile using --inspect, but I noticed that it never went above 20MB, so it was probably not a "normal" JavaScript leak. I think Deno lacks GC information in the DevTools profiler, so that wasn't helpful.
  2. I proceeded to compile Deno in debug mode, upload to VPS, run with the workload using LD_PRELOAD=/usr/lib/libtcmalloc.so and a HEAPPROFILE.
  3. The results were in. And looks like it's Intl.DateTimeFormat that is at fault.
    leak_result
  4. Then I looked for similar issues. Found: Memory leak when using Intl.DateTimeFormat.format() and Intl.NumberFormat.format() nodejs/node#31914, seems related, and listed as fixed for v8, but let's try the repro. Created a file leak.ts, ran with deno and watched the resident memory climb up to 5.4G. Ran with node, it also looks "leaky", but it only goes up to 1.3G.
setInterval(() => {
  var a;
  for (let i = 0; i < 100; i++) {
    a = new Intl.DateTimeFormat("en").format(Date.now());
  }
}, 1);
  1. The same code with a similar object, Intl.NumberFormat, peaks at 100M for node, and 258M for deno. I assume that is normal.
setInterval(() => {
  var a;
  for (let i = 0; i < 100; i++) {
    a = new Intl.NumberFormat("en").format(3);
  }
}, 1);
  1. I couldn't change this memory ceiling by using --v8-flags=--max-old-space-size, so I guess it's completely external to that.

I think it's probably an issue in V8 itself that has not been correctly resolved, and deno and node both handle it differently. I will try to change Temporal to reuse the same Intl.DateTimeFormat instance, for now, but it would be nice if this could be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlydeno_coreChanges in "deno_core" crate are needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions