node/doc/api
Andrew Casey 3772cf56ae
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` (3637a061a at the
time) on an Ubuntu Server desktop with an SSD.

PR-URL: https://github.com/nodejs/node/pull/33716
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2020-11-18 16:19:33 -05:00
..
addons.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
assert.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
async_hooks.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
buffer.md 2020-10-20, Version 15.0.0 (Current) 2020-10-20 15:42:45 +01:00
child_process.md doc: document the error when cwd not exists in child_process.spawn 2020-11-15 00:30:58 +01:00
cli.md doc: esm docs consolidation and reordering 2020-11-15 13:04:06 -08:00
cluster.md doc: sort md references in ASCII order 2020-10-01 06:19:25 -07:00
console.md doc: update console.error example 2020-10-24 16:11:26 +02:00
crypto.md doc: fix crypto doc linter errors 2020-11-08 05:14:56 -08:00
debugger.md doc: fix typo in debugger.md 2020-11-13 06:02:16 -08:00
deprecations.md 2020-11-04, Version 15.1.0 (Current) 2020-11-04 21:43:02 +01:00
dgram.md doc: harmonize changes list ordering 2020-10-09 18:46:47 +00:00
diagnostics_channel.md 2020-11-04, Version 15.1.0 (Current) 2020-11-04 21:43:02 +01:00
dns.md dns: add a cancel() method to the promise Resolver 2020-11-15 00:17:32 +01:00
documentation.md doc: sort md references in ASCII order 2020-10-01 06:19:25 -07:00
domain.md doc: fix missing PR-URLs in YAML comments 2020-10-09 18:46:45 +00:00
embedding.md 2020-10-20, Version 15.0.0 (Current) 2020-10-20 15:42:45 +01:00
errors.md http2: allow setting the local window size of a session 2020-11-11 23:14:56 +08:00
esm.md doc: esm docs consolidation and reordering 2020-11-15 13:04:06 -08:00
events.md events: add max listener warning for EventTarget 2020-11-16 09:48:18 +00:00
fs.md lib: add throws option to fs.f/l/statSync 2020-11-18 16:19:33 -05:00
globals.md 2020-10-20, Version 15.0.0 (Current) 2020-10-20 15:42:45 +01:00
http2.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
http.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
https.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
index.md lib: create diagnostics_channel module 2020-10-31 21:24:11 +00:00
inspector.md doc: use .md extension for internal links 2020-10-01 06:19:12 -07:00
intl.md doc: sort md references in ASCII order 2020-10-01 06:19:25 -07:00
module.md module: refactor to use iterable-weak-map 2020-11-06 12:47:23 -08:00
modules.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
n-api.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
net.md doc,net: document socket.timeout 2020-11-09 18:46:53 +01:00
os.md doc: use kbd element in os doc 2020-10-20 04:45:52 -07:00
packages.md 2020-11-04, Version 15.1.0 (Current) 2020-11-04 21:43:02 +01:00
path.md path: add path/posix and path/win32 alias modules 2020-10-20 14:27:31 +00:00
perf_hooks.md worker: add eventLoopUtilization() 2020-10-27 09:43:20 +01:00
policy.md doc: revise dependency redirection text in policy.md 2020-09-24 04:30:35 -07:00
process.md doc: clarify text about process not responding 2020-11-18 04:17:31 -08:00
punycode.md tools,doc: enforce alphabetical order for md refs 2020-09-22 10:25:43 -07:00
querystring.md doc: harmonize version list style in YAML comments 2020-10-09 18:46:45 +00:00
quic.md 2020-10-20, Version 15.0.0 (Current) 2020-10-20 15:42:45 +01:00
readline.md readline: add getPrompt to get the current prompt 2020-11-10 19:46:51 +00:00
repl.md doc: make small improvements to REPL doc 2020-10-28 06:29:39 -07:00
report.md src: add loop idle time in diagnostic report 2020-11-13 11:53:37 +05:30
stream.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
string_decoder.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
synopsis.md doc: use .md extension for internal links 2020-10-01 06:19:12 -07:00
timers.md doc: mark optional parameters in timers.md 2020-10-25 17:48:25 +05:30
tls.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
tracing.md doc: simplify wording in tracing APIs doc 2020-10-10 05:55:04 -07:00
tty.md doc: use kbd element in tty doc 2020-10-15 03:44:25 -07:00
url.md doc,url: fix url.hostname example 2020-11-18 19:53:41 +01:00
util.md doc: update list styles for remark-parse@9 rendering 2020-11-12 06:29:49 +00:00
v8.md doc: move v8.getHeapCodeStatistics() 2020-11-10 05:29:19 -08:00
vm.md doc: consolidate and clarify breakOnSigInt text 2020-10-27 11:34:16 +00:00
wasi.md wasi: drop --experimental-wasm-bigint requirement 2020-10-18 20:17:43 +02:00
webcrypto.md 2020-10-20, Version 15.0.0 (Current) 2020-10-20 15:42:45 +01:00
worker_threads.md doc: fix invalid link in worker_threads.md 2020-11-15 06:20:20 -08:00
zlib.md doc: fix YAML syntax errors 2020-10-06 15:52:10 -07:00