Uh oh!
There was an error while loading. Please reload this page.
n-api: optimize number API performance - #14573
Conversation
| size_t length, | ||
| napi_value* result); | ||
| NAPI_EXTERN napi_status napi_create_number(napi_env env, | ||
| NAPI_EXTERN napi_status napi_create_double(napi_env env, |
There was a problem hiding this comment.
I think we should keep supporting the name napi_create_number to avoid the – minor – breakage that this creates.
That can be as simple as
#definenapi_create_number napi_create_doublein the header and
#undef napi_create_number
napi_status napi_create_number(napi_env env, double value, napi_value* result) {
returnnapi_create_double(env, value, result);
}in the source file.
There was a problem hiding this comment.
Like, I know this is not pretty, but we should be prepared to see legacy fallbacks accumulate in N-API (and that’s okay, it’s literally N-API’s purpose to provide stability).
There was a problem hiding this comment.
There will be other breaking changes before N-API exits experimental status. While I acknowledge that sometime soon we need to stabilize and stop making breaking changes, I think it might be a bit too soon.
| static napi_status napi_set_last_error(napi_env env, napi_status error_code, | ||
| static inline | ||
| napi_status napi_set_last_error(napi_env env, napi_status error_code, | ||
| uint32_t engine_error_code, |
There was a problem hiding this comment.
The indentation here and below is off now.
mhdawson
commented
Aug 3, 2017
I think we should draw the line soon (say end of Aug) at which point we'll avoid breaking changes, but at this point I'm thinking since we know there will be a few others we might as well make this one as well. |
jasongin
commented
Aug 3, 2017
| v8::Local<v8::Context> context = isolate->GetCurrentContext(); | ||
| *result = val->Int32Value(context).FromJust(); | ||
| v8::Local<v8::Context> context; // empty context | ||
| *result = val->Int32Value(context).FromJust(); |
There was a problem hiding this comment.
Might be good to document why we are passing an empty context. A link to #14379 shall suffice.
jasongin
commented
Aug 8, 2017
CI failures were unrelated. Landed as af70c3b |
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: nodejs#14379 PR-URL: nodejs#14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: #14379 PR-URL: #14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Notable changes * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](nodejs/node#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](nodejs/node#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](nodejs/node#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](nodejs/node#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](nodejs/node#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](nodejs/node#14558) PR-URL: nodejs/node#14811
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: nodejs#14379 PR-URL: nodejs#14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: #14379 Backport-PR-URL: #19447 PR-URL: #14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
v8::TryCatch(NAPI_PREAMBLEmacro), because these functions have no possibility of executing JS code.Refs: #14379 (optimizations 1, 2, and 4)
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
n-api