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

fs: return stats to JS in sync methods #20167

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

  • Reduce reference to the global statValues by returning
    the changed stats array from the synchronous methods. Having
    a local returned value also makes the future integration
    of BigInt easier.
  • Also returns the filled array from node::FillGlobalStatsArray
    and node::FillStatsArray in the C++ side.
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

- Reduce reference to the global `statValues` by returning
  the changed stats array from the synchronous methods. Having
  a local returned value also makes the future integration
  of BigInt easier.
- Also returns the filled array from node::FillGlobalStatsArray
  and node::FillStatsArray in the C++ side.
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Apr 20, 2018
@joyeecheung
Copy link
Member Author

joyeecheung commented Apr 20, 2018

@joyeecheung
Copy link
Member Author

cc @nodejs/fs

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM if the benchmarks show no regression.

lib/fs.js Outdated
@@ -1682,10 +1685,10 @@ fs.realpathSync = function realpathSync(p, options) {

var baseLong = pathModule.toNamespacedPath(base);
const ctx = { path: base };
binding.lstat(baseLong, undefined, ctx);
const arr = binding.lstat(baseLong, undefined, ctx);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: arr seems pretty generic. Should it not be stats like everywhere else?

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Benchmarks look good 👍

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 22, 2018
@@ -1666,7 +1668,8 @@ fs.realpathSync = function realpathSync(p, options) {

// continue if not a symlink, break if a pipe/socket
if (knownHard[base] || (cache && cache.get(base) === base)) {
if (isFileType(S_IFIFO) || isFileType(S_IFSOCK)) {
if (isFileType(statValues, S_IFIFO) ||
isFileType(statValues, S_IFSOCK)) {
Copy link
Member

Choose a reason for hiding this comment

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

statValues is filled up by the binding.lstat() call ~20 lines up? Is the logic here still correct if the entry comes from the cache?

Apropos that lstat() call, maybe do this?

let stats;  // and use this in isFileType() calls
if (...) {
  const ctx = { path: base };
  stats = binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
  // ...
}

(Also applies to fs.realpath().)

Copy link
Member Author

Choose a reason for hiding this comment

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

In the current code statValues always equals to stats since neither side allocate any new stats arrays. I could try this but from the code it's very hard to tell if stats will be undefinedor not when you hit the use statement below.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, never mind then.

lib/fs.js Outdated
@@ -1820,14 +1824,14 @@ fs.realpath = function realpath(p, options, callback) {
return fs.lstat(base, gotStat);
}

function gotStat(err) {
function gotStat(err, stats) {
if (err) return callback(err);

// Use stats array directly to avoid creating an fs.Stats instance just for
// our internal use.
Copy link
Member

Choose a reason for hiding this comment

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

No longer true, is it?

@joyeecheung
Copy link
Member Author

@joyeecheung
Copy link
Member Author

Addressed the nits. CI is green, landing...

@joyeecheung
Copy link
Member Author

Landed in ce4c8c8, thanks!

joyeecheung added a commit that referenced this pull request Apr 23, 2018
- Reduce reference to the global `statValues` by returning
  the changed stats array from the synchronous methods. Having
  a local returned value also makes the future integration
  of BigInt easier.
- Also returns the filled array from node::FillGlobalStatsArray
  and node::FillStatsArray in the C++ side.

PR-URL: #20167
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Gus Caplan <me@gus.host>
jasnell pushed a commit that referenced this pull request Apr 23, 2018
- Reduce reference to the global `statValues` by returning
  the changed stats array from the synchronous methods. Having
  a local returned value also makes the future integration
  of BigInt easier.
- Also returns the filled array from node::FillGlobalStatsArray
  and node::FillStatsArray in the C++ side.

PR-URL: #20167
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Gus Caplan <me@gus.host>
@bzoz
Copy link
Contributor

bzoz commented May 16, 2018

This causes issues on Windows: #19831 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants