Skip to content

[wip] node-api: optimize finalizer queue using container swap #57861

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mertcanaltin
Copy link
Member

I replaced the iterative per-item removal with a swap to reduce the overhead

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/node-api

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. labels Apr 13, 2025
Copy link

codecov bot commented Apr 13, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.26%. Comparing base (964e41c) to head (61b9793).
Report is 72 commits behind head on main.

Files with missing lines Patch % Lines
src/node_api.cc 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57861      +/-   ##
==========================================
+ Coverage   90.23%   90.26%   +0.02%     
==========================================
  Files         630      630              
  Lines      185518   186170     +652     
  Branches    36369    36480     +111     
==========================================
+ Hits       167401   168044     +643     
+ Misses      11005    10984      -21     
- Partials     7112     7142      +30     
Files with missing lines Coverage Δ
src/node_api.cc 76.22% <85.71%> (+0.08%) ⬆️

... and 80 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption in the comment "userland code can delete additional references in one finalizer" will break with the new change.

However, this assumption was not reflected in test test/js-native-api/6_object_wrap/6_object_wrap.cc. Would you mind updating the test to verify deleting another reference in the destructor of MyObject?

MyObject::~MyObject() {
  napi_delete_reference(env_, nested_);
  napi_delete_reference(env_, wrapper_);
}

@mertcanaltin
Copy link
Member Author

The assumption in the comment "userland code can delete additional references in one finalizer" will break with the new change.

However, this assumption was not reflected in test test/js-native-api/6_object_wrap/6_object_wrap.cc. Would you mind updating the test to verify deleting another reference in the destructor of MyObject?

MyObject::~MyObject() {
  napi_delete_reference(env_, nested_);
  napi_delete_reference(env_, wrapper_);
}

I updated, thanks

@mertcanaltin
Copy link
Member Author

tests passed in my local environment for macos but I think there is a problem in linux I will try

@mertcanaltin mertcanaltin changed the title node-api: optimize finalizer queue using container swap [WIP] node-api: optimize finalizer queue using container swap Apr 15, 2025
@mertcanaltin mertcanaltin changed the title [WIP] node-api: optimize finalizer queue using container swap node-api: optimize finalizer queue using container swap Apr 22, 2025
@legendecas
Copy link
Member

#57861 (review) was not addressed.

The change proposed does not fulfill the behavior as described in the original comment:

node/src/node_api.cc

Lines 116 to 118 in 68cc1c9

// As userland code can delete additional references in one finalizer,
// the list of pending finalizers may be mutated as we execute them, so
// we keep iterating it until it is empty.

This change will crash the test #57981.

@mertcanaltin
Copy link
Member Author

#57861 (review) was not addressed.

The change proposed does not fulfill the behavior as described in the original comment:

node/src/node_api.cc

Lines 116 to 118 in 68cc1c9

// As userland code can delete additional references in one finalizer,
// the list of pending finalizers may be mutated as we execute them, so
// we keep iterating it until it is empty.

This change will crash the test #57981.

thanks I updated it as you indicated here
#57861 (comment)

@mertcanaltin mertcanaltin changed the title node-api: optimize finalizer queue using container swap [wip] node-api: optimize finalizer queue using container swap Apr 24, 2025
@mhdawson mhdawson moved this from Need Triage to In Progress in Node-API Team Project Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants