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

perf(node/fs): faster existsSync when not exists #21458

Merged
merged 7 commits into from
Dec 4, 2023

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Dec 4, 2023

% ./target/release/deno bench -A exists.bench.ts
Check file:https:///Users/david/dev/deno/exists.bench.ts
cpu: Apple M2 Pro
runtime: deno 1.38.4 (aarch64-apple-darwin)

file:https:///Users/david/dev/deno/exists.bench.ts
benchmark               time (avg)        iter/s             (min … max)       p75       p99      p995
------------------------------------------------------------------------ -----------------------------
std/existsSync          19.23 µs/iter      51,996.7  (17.21 µs … 348.29 µs)  19.29 µs  22.67 µs  24.25 µs
node:fs existsSync       6.24 µs/iter     160,376.3     (6.19 µs … 6.42 µs)   6.25 µs   6.42 µs   6.42 µs

Raises the point that we need to get std's existsSync to be faster.

ext/fs/ops.rs Outdated Show resolved Hide resolved
Deno.lstatSync(path);
return true;
} catch (_err) {
return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

One other thing this fixes is previously this would supress permission errors.

Copy link
Member

Choose a reason for hiding this comment

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

IIRC this was done on purpose, but seems fishy. @kt3k any idea here?

Copy link
Member Author

Choose a reason for hiding this comment

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

If intentional, my guess would be to reduce permission prompts, but I don't think we should do that because it causes subtle bugs.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like it was for avoiding to throw 'Not a directory' error when called with non-existing dir denoland/deno_std#2494

cli/tests/unit_node/fs_test.ts Outdated Show resolved Hide resolved
ext/fs/ops.rs Outdated Show resolved Hide resolved
Deno.lstatSync(path);
return true;
} catch (_err) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

IIRC this was done on purpose, but seems fishy. @kt3k any idea here?

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM

@dsherret dsherret enabled auto-merge (squash) December 4, 2023 20:41
@dsherret dsherret merged commit a24d3e8 into denoland:main Dec 4, 2023
14 checks passed
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 this pull request may close these issues.

None yet

3 participants