-
Notifications
You must be signed in to change notification settings - Fork 198
Closed
Description
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.
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
Metadata
Metadata
Assignees
Labels
No labels