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

node-api: remove RefBase and CallbackWrapper #53590

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

Conversation

vmoroz
Copy link
Member

@vmoroz vmoroz commented Jun 25, 2024

This PR simplifies internal Node-API implementation to reduce the code complexity and to reduce allocated memory size.
There are no API changes or changes to the code behavior. All existing tests are passing and no new tests are needed.

  • Removed RefBase class.
    • Reference class directly inherits from RefTracker.
    • napi_set_instance_data and napi_get_instance_data use TrackedFinalizer instead of RefBase.
  • v8impl::Ownership enum is renamed to v8impl::ReferenceOwnership to better reflect its purpose.
    • v8impl::ReferenceOwnership size changed to one byte to reduce Reference size.
  • Finalizer class became non-virtual to reduce its size.
    • All Finalizer fields became private for better encapsulation.
    • TrackedFinalizer and TrackedStringResource size changed from 64 to 56 bytes on 64-bit platforms.
  • Reference class is split up into three classes depending on the usage scenario: Reference, ReferenceWithData, and ReferenceWithFinalizer.
    • Previously Reference instance size on 64-bit platforms was 88 bytes.
    • New Reference size is 40 bytes, ReferenceWithData is 48 bytes, and ReferenceWithFinalizer is 72 bytes.
    • ReferenceWithFinalizer size reduced by 16 bytes due to changes to Finalizer (8 bytes) and removal of RefBase that along with the v8impl::ReferenceOwnership to be one byte gained reduction of another 8 bytes.
    • Instances of Reference and ReferenceWithData are not queued for finalization since they do not have user finalizer callbacks. They are finalized immediately.
  • Simplified FunctionCallbackWrapper.
    • Removed base classes CallbackWrapper and CallbackWrapperBase
    • All methods became non-virtual.
    • It should slightly improve perf for each function call.

@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 Jun 25, 2024
src/js_native_api_v8.cc Outdated Show resolved Hide resolved
@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 27, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 27, 2024
@nodejs-github-bot
Copy link
Collaborator

src/node_api.cc Outdated Show resolved Hide resolved
src/js_native_api_v8.cc Show resolved Hide resolved
src/js_native_api_v8.cc Show resolved Hide resolved
src/js_native_api_v8.h Outdated Show resolved Hide resolved
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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants