Skip to content

Using v8::Private::ForApi for N-API object wrapping #14367

Description

@TimothyGu
  • Version: master
  • Platform: all
  • Subsystem: n-api

Currently, N-API's object wrapping uses v8::External with a const char* as a brand check. However, v8::Externals are known to be inefficient, and the fact that one such External is created for every wrapped object only worsens the problem. On the other hand, V8 provides the mechanism necessary for cross-napi_env brand checks in v8::Private::ForApi, which is like a C++-private version of Symbol.for(), and v8::Object::HasPrivate/SetPrivate. Handles to these v8::Privates can then be cached per napi_env in a Persistent. Similar features are also available in earlier V8 versions, as implemented in @kkoopa's NAN.

I'd be willing to cook up a PR for this.

/cc @nodejs/n-api @gabrielschulhof @jasongin

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    node-apiIssues and PRs related to Node-API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions