Skip to content
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

v8.serialize leaks memory #40828

Closed
JLHwung opened this issue Nov 16, 2021 · 3 comments · Fixed by #42695
Closed

v8.serialize leaks memory #40828

JLHwung opened this issue Nov 16, 2021 · 3 comments · Fixed by #42695
Labels
v8 module Issues and PRs related to the "v8" subsystem.

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Nov 16, 2021

Version

v17.0.1

Platform

21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000 arm64

Subsystem

v8

What steps will reproduce the bug?

Run the following snippet

const { serialize } = require("v8");
const { memoryUsage } = process;

for (let i = 0; i < 1 << 22; i++) {
  serialize({});

  if (i % (1 << 15) === 0) {
    console.log(
      `RSS: ${Math.round((memoryUsage().rss / 1024 / 1024) * 100) / 100} MiB`
    );
  }
}

How often does it reproduce? Is there a required condition?

Must reproduce

What is the expected behavior?

The RSS in the stdout should converges to some tens of MiB. For example, if v8.serialize is replaced by JSON.stringify, the RSS is stablized at 33.89MiB.

What do you see instead?

The RSS keeps rising indefinitely.

Additional information

Also affected: v16.0.0

Additional context: babel/babel#13970

@Mesteery Mesteery added the v8 module Issues and PRs related to the "v8" subsystem. label Nov 16, 2021
@cjihrig
Copy link
Contributor

cjihrig commented Nov 16, 2021

It doesn't look like you're giving the garbage collector a chance to run. Does the memory get collected once the loop is exited?

@JLHwung
Copy link
Contributor Author

JLHwung commented Nov 16, 2021

Does the memory get collected once the loop is exited?

I still see memory surging when I invoke gc every 1 << 15 times.

const { serialize } = require("v8");
const { memoryUsage } = process;

for (let i = 0; i < 1 << 22; i++) {
  serialize({});

  if (i % (1 << 15) === 0) {
    gc();
    console.log(
      `RSS: ${Math.round((memoryUsage().rss / 1024 / 1024) * 100) / 100} MiB`
    );
  }
}

@ppedziwiatr
Copy link

Same issue observed on various x86 CPUs and node 16.x and 17x.

The issue doesn't seem to occur on my M1 though.

liuxingbaoyu added a commit to liuxingbaoyu/node that referenced this issue Apr 11, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: nodejs#40828
Refs: nodejs#38300
liuxingbaoyu added a commit to liuxingbaoyu/node that referenced this issue Apr 11, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: nodejs#40828
Refs: nodejs#38300
nodejs-github-bot pushed a commit that referenced this issue May 2, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
RafaelGSS pushed a commit that referenced this issue May 10, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
juanarbol pushed a commit that referenced this issue May 31, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
danielleadams pushed a commit that referenced this issue Jun 27, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
targos pushed a commit that referenced this issue Jul 12, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
targos pushed a commit that referenced this issue Jul 31, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: #40828
Refs: #38300

PR-URL: #42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
guangwong pushed a commit to noslate-project/node that referenced this issue Oct 10, 2022
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.

Fixes: nodejs/node#40828
Refs: nodejs/node#38300

PR-URL: nodejs/node#42695
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 module Issues and PRs related to the "v8" subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants