Skip to content

Long Major GC events while using external buffers (Video Image Data) #55627

Open
@david-metrica

Description

@david-metrica

Version

v23.1.0

Platform

23.1.0 Darwin Kernel Version 23.1.0

Subsystem

No response

What steps will reproduce the bug?

I am sharing data from a native node C++ plugin using node-addon-api: return Napi::ArrayBuffer::New(env, frame_->data[i], width*height);

I checked that the memory being accessed from JS was the same as the one from C++ (And can confirm it works as expected).

However, whenever I access this data I get some Major GC events taking more than 100+ms in total.
image

The memory is freed by the C++ process and there is not any crash or weird behavior apart from this.

The ArrayBuffer is exposed using node-addon-api: InstanceAccessor("data", &Frame::data, nullptr), .

Writing frame.data in javascript causes this events.

node-addon-api uses napi_create_external_buffer when creating a Napi::ArrayBuffer

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

This occurs multiple times every 1-2s. Depends on the size of the data and how often is sent from C++ to JS.

What is the expected behavior? Why is that the expected behavior?

As the memory collection is not handled by the Major GC it should not expend time trying to free this objects.

What do you see instead?

Major GC trying to collect external buffers and spending more time depending how big this external buffers are.

Additional information

No response

Metadata

Metadata

Assignees

Labels

node-apiIssues and PRs related to the Node-API.

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions