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

Use throwIfNoEntry for sync resolver once graceful-fs supports it #316

Closed
markjm opened this issue Nov 1, 2021 · 1 comment · Fixed by #324
Closed

Use throwIfNoEntry for sync resolver once graceful-fs supports it #316

markjm opened this issue Nov 1, 2021 · 1 comment · Fixed by #324

Comments

@markjm
Copy link
Contributor

markjm commented Nov 1, 2021

For cases of using sync resolver, throwIfNoEntry improves stat fail case by a large margin. The API in node is backwards compatible, so we should just be able to add this option and be on our way.

Unfortunately, there is an issue with this option in graceful-fs, so I have opened an issue there. Once resolved, this should be unblocked and easy change here.

isaacs/node-graceful-fs#221

const fs = require("fs");
function oldStat(path) {
  let stat;

  try {
    stat = fs.statSync(path);
  } catch (e) {
    if (!(e && (e.code === "ENOENT" || e.code === "ENOTDIR"))) {
      throw e;
    }
  }
}

console.time("oldStat");
for (let i = 0; i < 100000; i++) oldStat("not-real-path");
console.timeEnd("oldStat"); // 6.7s

function newStat(path) {
  let stat = fs.statSync(path, { throwIfNoEntry: false });

}

console.time("newStat");
for (let i = 0; i < 100000; i++) newStat("not-real-path");
console.timeEnd("newStat"); // 2.1s
@alexander-akait
Copy link
Member

Make sense, PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants