Skip to content

N-API: Reuse ObjectTemplate used for napi_wrap() - #13999

Closed
gabrielschulhof wants to merge 1 commit into
nodejs:masterfrom
gabrielschulhof:reuse-wrap-template
Closed

N-API: Reuse ObjectTemplate used for napi_wrap()#13999
gabrielschulhof wants to merge 1 commit into
nodejs:masterfrom
gabrielschulhof:reuse-wrap-template

Conversation

@gabrielschulhof

Copy link
Copy Markdown
Contributor

V8 caches and does not subsequently release ObjectTemplate instances.
Thus, we need to store the ObjectTemplate from which we derive object
instances we use for napi_wrap() in a persistent in the napi_env.

Re nodejs/node-addon-api#70 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

N-API

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. node-api Issues and PRs related to the Node-API. labels Jun 30, 2017
@gabrielschulhof

Copy link
Copy Markdown
ContributorAuthor

This means we will have one ObjectTemplate per N-API module, because we have one napi_env per N-API module.

@gabrielschulhof

Copy link
Copy Markdown
ContributorAuthor

Whoops! Wrong template :) BRB

@gabrielschulhof

Copy link
Copy Markdown
ContributorAuthor

Hmmm ... we actually use more than one ObjectTemplate. Need to store 'em all on the napi_env.

@gabrielschulhof

Copy link
Copy Markdown
ContributorAuthor

OK, now we're good. Three ObjectTemplate instances stored on the napi_env. So, three ObjectTemplate instances per module. Granted, they're lazy, so an ObjectInstance is only created if

  • a module does any wrapping (not necessarily though often)
  • a module implements accessors (perhaps more rarely)
  • a module exports native functions (almost always)

Comment threadsrc/node_api.cc Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you indent by 4 spaces?

V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)

@mhdawsonmhdawson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@mhdawson

Copy link
Copy Markdown
Member

@mhdawson

Copy link
Copy Markdown
Member

Landed as 29df1a8

@mhdawsonmhdawson closed this Jul 6, 2017
mhdawson pushed a commit that referenced this pull request Jul 6, 2017
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
PR-URL: #13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
@gabrielschulhof
gabrielschulhof deleted the reuse-wrap-template branch July 6, 2017 18:39
addaleax pushed a commit that referenced this pull request Jul 11, 2017
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
PR-URL: #13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
@addaleax

Copy link
Copy Markdown
Member

@gabrielschulhof@mhdawson Just so you know, if you don’t provide the subsystem in the commit message in lowercase the tooling won’t group it properly in the changelog – not a big deal, just something for the future. :)

@addaleaxaddaleax mentioned this pull request Jul 11, 2017
@gibfahn

Copy link
Copy Markdown
Member

if you don’t provide the subsystem in the commit message in lowercase the tooling won’t group it properly in the changelog – not a big deal, just something for the future. :)

If we don't have any uppercase subsystems (which I think is the case) then maybe core-validate-commit could check for that.

@evanlucas

Copy link
Copy Markdown
Contributor

it checks for a certain set of subsystems, so it should have failed for that as well.

 ✖ 29df1a87fa230bc86f460620173b9fedd2919f68
✔ 0:0 skipping fixes-url fixes-url
✔ 0:0 blank line after title line-after-title
✔ 0:0 line-lengths are valid line-length
✔ 0:0 metadata is at end of message metadata-end
✔ 0:0 reviewers are valid reviewers
✖ 0:0 Invalid subsystem: "N-API" subsystem
✔ 0:0 Title is <= 50 columns. title-length

:]

addaleax pushed a commit that referenced this pull request Jul 18, 2017
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
PR-URL: #13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
Fishrock123 pushed a commit that referenced this pull request Jul 19, 2017
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
PR-URL: #13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Apr 10, 2018
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
PR-URL: nodejs#13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
MylesBorins pushed a commit that referenced this pull request Apr 16, 2018
V8 caches and does not subsequently release `ObjectTemplate` instances.
Thus, we need to store the `ObjectTemplate` from which we derive object
instances we use for `napi_wrap()` and function/accessor context in a
persistent in the `napi_env`.
nodejs/node-addon-api#70 (comment)
Backport-PR-URL: #19447
PR-URL: #13999
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.co>
Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
@MylesBorinsMylesBorins mentioned this pull request Apr 16, 2018
Sign up for freeto 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++.node-apiIssues and PRs related to the Node-API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@gabrielschulhof@mhdawson@addaleax@gibfahn@evanlucas@digitalinfinity@bnoordhuis@jasnell@cjihrig@MylesBorins@nodejs-github-bot