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: improve process.hrtime #10764

Closed
wants to merge 1 commit into from

Conversation

joyeecheung
Copy link
Member

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
Affected core subsystem(s)

process

This PR is split into two commits in caution of breaking change, can be squashed when identified not breaking. Non breaking:

  • Add benchmarks for diffing a previous result
  • Improvements to the documentation, including type annotation
  • Update the oudated comments in src/node.cc
  • Comment process.hrtime and improve readability

Might be breaking: check the length of argument passed into process.hrtime(). Passing a user-defined array is previously described as undefined behavior in the documentation.

Benchmark results:

                                               improvement significant   p.value
 process/bench-hrtime.js type="diff" n=1000000      0.28 %             0.8029355
 process/bench-hrtime.js type="raw" n=1000000      -0.56 %             0.6488252

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. process Issues and PRs related to the process subsystem. dont-land-on-v7.x labels Jan 12, 2017
@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 12, 2017
@jasnell
Copy link
Member

jasnell commented Jan 12, 2017

Unfortunately because of the change in error condition this has to be labeled as semver-major.

const nsec = hrValues[2] - ar[1];
return [nsec < 0 ? sec - 1 : sec, nsec < 0 ? nsec + 1e9 : nsec];
if (time !== undefined) {
if (Array.isArray(time) && time.length == 2) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: === for comparison

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed.

@addaleax
Copy link
Member

Unfortunately because of the change in error condition this has to be labeled as semver-major.

I don’t think it has to be. As @joyeecheung mentioned in the PR description, this only adds a throw for situations that we explicitly declared to be undefined behavior in the docs. It’s probably best to consider it breaking, unless there’s a good reason not to do that.

const n = conf.n >>> 0;
const n = conf.n | 0;
const hrtime = process.hrtime;
var noDead = hrtime(), i;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please make these separate var statements?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed

@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

@jasnell If you still think it is semver-major, I am OK with landing this as semver-major.

@jasnell
Copy link
Member

jasnell commented Jan 15, 2017

I'm more comfortable landing it as semver-major

@addaleax
Copy link
Member

CI: https://ci.nodejs.org/job/node-test-commit/7257/ (Started this without seeing that one had already been kicked off. Sorry!)
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/525/

@joyeecheung
Copy link
Member Author

Going to land this if there is nothing else to be addressed. @mscdex Does this LGTY?

process.hrtime([]);
}, /^TypeError: process.hrtime\(\) only accepts an Array tuple$/);
assert.throws(() => {
process.hrtime([1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding another test that has > 2 elements?

@mscdex
Copy link
Contributor

mscdex commented Jan 17, 2017

One nit, but I agree with @jasnell that I would lean more towards semver-major to be on the safe side. Otherwise LGTM.

* Add benchmarks for diffing a previous result
* Improvements to the documentation, including type annotation
* Update the outdated comments in src/node.cc, improve comments
  in lib/internal/process.js
* Check the argument is an Array Tuple with length 2
@joyeecheung
Copy link
Member Author

joyeecheung added a commit that referenced this pull request Jan 23, 2017
* Add benchmarks for diffing a previous result
* Improvements to the documentation, including type annotation
* Update the outdated comments in src/node.cc, improve comments
  in lib/internal/process.js
* Check the argument is an Array Tuple with length 2

PR-URL: #10764
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Brian White <[email protected]>
@joyeecheung
Copy link
Member Author

Landed in a647d82

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++. process Issues and PRs related to the process subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants