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

process: implement process.hrtime.bigint() #21256

Closed
wants to merge 2 commits into
base: master
from

Conversation

@joyeecheung
Copy link
Member

joyeecheung commented Jun 11, 2018

The first commit is from #21255

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@joyeecheung joyeecheung force-pushed the joyeecheung:bigint-hrtime branch from 84cd2cd to f7ba146 Jun 11, 2018

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 11, 2018

message: 'The "time" argument must be of type bigint. Received type object'
});

// The default behavior, return an Array "tuple" of numbers

This comment has been minimized.

@joyeecheung

joyeecheung Jun 11, 2018

Author Member

Oops, copy-paste error..

@devsnek
Copy link
Member

devsnek left a comment

is it still a perf boost to use the ArrayBuffer when it's just one value?

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 11, 2018

@devsnek I don't think it makes much difference, probably can save an allocation depending on the situation though.

setTimeout(() => {
const diff = process.hrtime.bigint(time);
// 1552n

This comment has been minimized.

@TimothyGu

TimothyGu Jun 11, 2018

Member

Was this supposed to be 1000000552n?


If `time` is specified, it must be the result of a previous
`process.hrtime.bigint()` call. The returned result will be the difference
between the current time and the specified time.

This comment has been minimized.

@TimothyGu

TimothyGu Jun 11, 2018

Member

While useful for the array-based method, I don’t think this feature is that useful now one can just subtract the times directly…

This comment has been minimized.

@joyeecheung

joyeecheung Jun 11, 2018

Author Member

@TimothyGu Yeah come to think of it, it does seem unnecessary. I'll remove it.

src/node.cc Outdated
void HrtimeBigInt(const FunctionCallbackInfo<Value>& args) {
Local<ArrayBuffer> ab = args[0].As<BigUint64Array>()->Buffer();
uint64_t* fields = static_cast<uint64_t*>(ab->GetContents().Data());
fields[0] = uv_hrtime();

This comment has been minimized.

@TimothyGu

TimothyGu Jun 11, 2018

Member

I’d also appreciate some benchmarking showing that the ArrayBuffer-based approach is faster than just returning the bigint.

This comment has been minimized.

@joyeecheung

joyeecheung Jun 11, 2018

Author Member

@TimothyGu There are no APIs for constructing a BigInt out of a uint64_t at the moment, it seems.

This comment has been minimized.

@joyeecheung

joyeecheung Jun 11, 2018

Author Member

I could add one for uint64_t, but there is a discussion going on about the general API design of BigInt: https://bugs.chromium.org/p/v8/issues/detail?id=7712 A simple overload would be ambiguous anyway.

@targos

targos approved these changes Jun 12, 2018


Unlike [`process.hrtime()`][], it does not support an additional `time`
argument since the difference can just be computed directly
by substraction of the two `bigint`s.

This comment has been minimized.

@targos

targos Jun 12, 2018

Member

subtraction

// 191052633396993n
console.log(`Benchmark took ${end - start} nanoseconds`);
// benchmark took 1154389282 nanoseconds

This comment has been minimized.

@vsemozhetbyt

vsemozhetbyt Jun 12, 2018

Member

benchmark -> Benchmark?

@apapirovski
Copy link
Member

apapirovski left a comment

I'm +1 on the addition but I'm not a fan of the scoping. Has there been some discussion around this? Personally I'm not a huge fan of putting bigint functions on top of existing functions. The naming ends up being pretty non-obvious plus it's an extra property lookup. Even hrtimeBigInt is more appealing to me, personally.

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 13, 2018

@apapirovski The naming is following the convention of fs.realpath.native, this is the best I can think of in terms of readability since adding another overload to the process.hrtime([time]) would be quite confusing and unlike the fs.*stats methods, it is unlikely to need another variant (e.g. temporal) in the future.

The extra lookup can be avoided if the user assign the function to an identifier first (also if they are already using process.hrtime then the overhead of that extra lookup may be irrelevant considering process is already pretty complex).

Another idea would be to expose a symbol similar to util.promisify.custom but that may bring in too much redirection overhead and it's hard to get it play along with other symbols if we stick to that pattern.

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 13, 2018

For reference: there is also heycam/webidl#525 and w3c/IndexedDB#231

cc @littledan do you have any suggestion regarding how to expose variants of existing APIs that support BigInt?

@TimothyGu
Copy link
Member

TimothyGu left a comment

LGTM other than the doc nit.

src/node.cc Outdated
@@ -1580,6 +1581,9 @@ static void Kill(const FunctionCallbackInfo<Value>& args) {
#define NANOS_PER_SEC 1000000000

// Hrtime exposes libuv's uv_hrtime() high-resolution timer.

// This is the legacy version of hrtime before BigInt was introduced in
// JavaScript.

This comment has been minimized.

@TimothyGu

TimothyGu Jun 15, 2018

Member

Hmm, seeing this we probably want a note in the documentation for process.hrtime() that the BigInt equivalent is preferred.

joyeecheung added some commits Jun 11, 2018

@joyeecheung joyeecheung force-pushed the joyeecheung:bigint-hrtime branch from 1ff4825 to b4d45ba Jun 16, 2018

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 16, 2018

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 17, 2018

CI is green. @apapirovski is your review in #21256 (review) blocking?

@apapirovski
Copy link
Member

apapirovski left a comment

@joyeecheung nope, it wasn't. :)

@joyeecheung

This comment has been minimized.

Copy link
Member Author

joyeecheung commented Jun 17, 2018

Landed in 1d8a231, thanks!

joyeecheung added a commit that referenced this pull request Jun 17, 2018

process: implement process.hrtime.bigint()
PR-URL: #21256
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
@targos

This comment has been minimized.

Copy link
Member

targos commented Jun 19, 2018

Depends on #21105 to land on v10.x-staging.

@targos targos referenced this pull request Jun 20, 2018

Closed

process: split bootstrappers by threads that can run them #21378

2 of 2 tasks complete

targos added a commit that referenced this pull request Jul 14, 2018

process: implement process.hrtime.bigint()
PR-URL: #21256
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

targos added a commit that referenced this pull request Jul 17, 2018

2018-07-18, Version 10.7.0 (Current)
Notable changes:

* console:
  * The `console.timeLog()` method has been implemented. (#21312)
* deps:
  * Upgrade to libuv 1.22.0. (#21731)
  * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728)
* http:
  * Added support for passing both `timeout` and `agent` options to
    `http.request`. (#21204)
* napi:
  * Added experimental support for functions dealing with bigint numbers. (#21226)
* process:
  * The `process.hrtime.bigint()` method has been implemented. (#21256)
  * Added the `--title` command line argument to set the process title on
    startup. (#21477)
* trace_events:
  * Added process_name metadata. (#21477)

@targos targos referenced this pull request Jul 17, 2018

Merged

v10.7.0 proposal #21851

targos added a commit that referenced this pull request Jul 18, 2018

2018-07-18, Version 10.7.0 (Current)
Notable changes:

* console:
  * The `console.timeLog()` method has been implemented. (#21312)
* deps:
  * Upgrade to libuv 1.22.0. (#21731)
  * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728)
* http:
  * Added support for passing both `timeout` and `agent` options to
    `http.request`. (#21204)
* napi:
  * Added experimental support for functions dealing with bigint numbers. (#21226)
* process:
  * The `process.hrtime.bigint()` method has been implemented. (#21256)
  * Added the `--title` command line argument to set the process title on
    startup. (#21477)
* trace_events:
  * Added process_name metadata. (#21477)
* Added new collaborators
  * codebytere - Shelley Vohr

PR-URL: #21851

targos added a commit that referenced this pull request Jul 18, 2018

2018-07-18, Version 10.7.0 (Current)
Notable changes:

* console:
  * The `console.timeLog()` method has been implemented. (#21312)
* deps:
  * Upgrade to libuv 1.22.0. (#21731)
  * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1). (#21728)
* http:
  * Added support for passing both `timeout` and `agent` options to
    `http.request`. (#21204)
* napi:
  * Added experimental support for functions dealing with bigint numbers. (#21226)
* process:
  * The `process.hrtime.bigint()` method has been implemented. (#21256)
  * Added the `--title` command line argument to set the process title on
    startup. (#21477)
* trace_events:
  * Added process_name metadata. (#21477)
* Added new collaborators
  * codebytere - Shelley Vohr

PR-URL: #21851

targos added a commit that referenced this pull request Jul 18, 2018

2018-07-18, Version 10.7.0 (Current)
Notable changes:

* console:
  * The `console.timeLog()` method has been implemented.
    (#21312)
* deps:
  * Upgrade to libuv 1.22.0. (#21731)
  * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1).
    (#21728)
* http:
  * Added support for passing both `timeout` and `agent` options to
    `http.request`. (#21204)
* inspector:
  * Expose the original console API in `require('inspector').console`.
    (#21659)
* napi:
  * Added experimental support for functions dealing with bigint numbers.
    (#21226)
* process:
  * The `process.hrtime.bigint()` method has been implemented.
    (#21256)
  * Added the `--title` command line argument to set the process title on
    startup. (#21477)
* trace_events:
  * Added process_name metadata.
    (#21477)
* Added new collaborators
  * codebytere - Shelley Vohr

PR-URL: #21851

targos added a commit that referenced this pull request Jul 18, 2018

2018-07-18, Version 10.7.0 (Current)
Notable changes:

* console:
  * The `console.timeLog()` method has been implemented.
    (#21312)
* deps:
  * Upgrade to libuv 1.22.0. (#21731)
  * Upgrade to ICU 62.1 (Unicode 11, CLDR 33.1).
    (#21728)
* http:
  * Added support for passing both `timeout` and `agent` options to
    `http.request`. (#21204)
* inspector:
  * Expose the original console API in `require('inspector').console`.
    (#21659)
* napi:
  * Added experimental support for functions dealing with bigint numbers.
    (#21226)
* process:
  * The `process.hrtime.bigint()` method has been implemented.
    (#21256)
  * Added the `--title` command line argument to set the process title on
    startup. (#21477)
* trace_events:
  * Added process_name metadata.
    (#21477)
* Added new collaborators
  * codebytere - Shelley Vohr

PR-URL: #21851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.