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

lib: add throws option to fs.f/l/statSync #33716

Closed
wants to merge 4 commits into from

Commits on Nov 10, 2020

  1. lib: add throws option to fs.f/l/statSync

    For consumers that aren't interested in *why* a `statSync` call failed,
    allocating and throwing an exception is an unnecessary expense.  This PR
    adds an option that will cause it to return `undefined` in such cases
    instead.
    
    As a motivating example, the JavaScript & TypeScript language service
    shared between Visual Studio and Visual Studio Code is stuck with
    synchronous file IO for architectural and backward-compatibility
    reasons.  It frequently needs to speculatively check for the existence
    of files and directories that may not exist (and cares about file vs
    directory, so `existsSync` is insufficient), but ignores file system
    entries it can't access, regardless of the reason.
    
    Benchmarking the language service is difficult because it's so hard to
    get good coverage of both code bases and user behaviors, but, as a
    representative metric, we measured batch compilation of a few hundred
    popular projects (by star count) from GitHub and found that, on average,
    we saved about 1-2% of total compilation time.  We speculate that the
    savings could be even more significant in interactive (language service
    or watch mode) scenarios, where the same (non-existent) files need to be
    polled over and over again.  It's not a huge improvement, but it's a
    very small change and it will affect a lot of users (and CI runs).
    
    For reference, our measurements were against `v12.x` (3637a06 at the
    time) on an Ubuntu Server desktop with an SSD.
    amcasey committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    156d248 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b3ea0b8 View commit details
    Browse the repository at this point in the history
  3. Drop option from fstatSync

    amcasey committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    f5836e8 View commit details
    Browse the repository at this point in the history
  4. Update test/parallel/test-fs-stat-bigint.js

    Co-authored-by: Michaël Zasso <[email protected]>
    amcasey and targos committed Nov 10, 2020
    Configuration menu
    Copy the full SHA
    a1815fb View commit details
    Browse the repository at this point in the history