Skip to content

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

Closed

Description

@markjm

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

Activity

  1. alexander-akait commented on Nov 2, 2021

    @alexander-akait
    Member

    Make sense, PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions