node/lib
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
..
assert assert: add assert/strict alias module 2020-06-25 08:37:48 -07:00
dns
fs
internal fs: filehandle read now accepts object as argument 2020-11-18 19:50:44 +01:00
path path: add path/posix and path/win32 alias modules 2020-10-20 14:27:31 +00:00
stream stream: add promises version to utility functions 2020-07-09 09:12:19 +02:00
timers timers: refactor to use more primordials 2020-11-18 04:21:24 -08:00
util util: add util/types alias module 2020-10-21 01:26:34 +02:00
_http_agent.js lib: remove ERR_INVALID_OPT_VALUE and ERR_INVALID_OPT_VALUE_ENCODING 2020-09-11 17:54:42 +03:00
_http_client.js lib: change http client path assignment 2020-10-08 21:42:39 +00:00
_http_common.js http: add requestTimeout 2020-09-15 15:39:54 -04:00
_http_incoming.js http: lazy create IncomingMessage.headers 2020-10-27 09:29:32 +01:00
_http_outgoing.js http: onFinish will not be triggered again when finished 2020-11-13 01:25:26 +08:00
_http_server.js http: report request start and end with diagnostics_channel 2020-10-31 21:24:12 +00:00
_stream_duplex.js stream: move to internal/streams 2020-09-21 08:23:06 +00:00
_stream_passthrough.js stream: move to internal/streams 2020-09-21 08:23:06 +00:00
_stream_readable.js stream: move to internal/streams 2020-09-21 08:23:06 +00:00
_stream_transform.js stream: move to internal/streams 2020-09-21 08:23:06 +00:00
_stream_wrap.js
_stream_writable.js stream: move to internal/streams 2020-09-21 08:23:06 +00:00
_tls_common.js src,crypto: refactoring of crypto_context, SecureContext 2020-11-11 12:05:32 -08:00
_tls_wrap.js tls: allow reading data into a static buffer 2020-10-28 16:07:29 +03:00
.eslintrc.yaml tools,lib: recommend using safe primordials 2020-11-09 19:05:41 +00:00
assert.js assert,repl: enable ecmaVersion 2021 in acorn parser 2020-10-30 14:52:28 +00:00
async_hooks.js async_hooks: fix leak in AsyncLocalStorage exit 2020-11-11 11:32:50 +00:00
buffer.js lib: use remaining typed arrays from primordials 2020-10-07 13:44:21 +00:00
child_process.js win, child_process: sanitize env variables 2020-09-24 18:25:18 +02:00
cluster.js
console.js
constants.js
crypto.js crypto: add getCipherInfo method 2020-10-13 09:30:53 -07:00
dgram.js dgram: allow typed arrays in .send() 2020-06-19 07:40:11 -07:00
diagnostics_channel.js lib: create diagnostics_channel module 2020-10-31 21:24:11 +00:00
dns.js net: add support for resolving DNS CAA records 2020-10-16 10:21:32 +02:00
domain.js domain: improve deprecation warning text for DEP0097 2020-11-18 18:58:49 +00:00
events.js events: add max listener warning for EventTarget 2020-11-16 09:48:18 +00:00
fs.js lib: add throws option to fs.f/l/statSync 2020-11-18 16:19:33 -05:00
http2.js http2: add support for sensitive headers 2020-07-16 00:25:47 +02:00
http.js
https.js https: set requestTimeout default to 0 2020-09-21 08:32:26 -07:00
inspector.js
module.js
net.js net: fix invalid write after end error 2020-11-11 00:27:13 +01:00
os.js lib: use Number.parseInt from primordials 2020-10-07 13:44:20 +00:00
path.js
perf_hooks.js perf_hooks: make nodeTiming a first-class object 2020-11-15 00:32:41 +01:00
process.js
punycode.js
querystring.js querystring: reduce memory usage by Int8Array 2020-11-10 20:22:08 +00:00
readline.js readline: add getPrompt to get the current prompt 2020-11-10 19:46:51 +00:00
repl.js lib: use Number.parseFloat from primordials 2020-10-07 13:44:21 +00:00
stream.js stream: fix legacy pipe error handling 2020-09-23 04:33:05 -07:00
string_decoder.js
sys.js
timers.js lib: use Object static properties from primordials 2020-09-30 17:52:35 +02:00
tls.js lib: replace String global with primordials 2020-10-04 09:40:56 +02:00
trace_events.js
tty.js
url.js querystring: reduce memory usage by Int8Array 2020-11-10 20:22:08 +00:00
util.js tools: add new ESLint rule: prefer-primordials 2020-11-07 18:28:14 +08:00
v8.js tools: add new ESLint rule: prefer-primordials 2020-11-07 18:28:14 +08:00
vm.js vm: refactor to use more primordials 2020-11-14 14:46:19 +00:00
wasi.js lib: replace String global with primordials 2020-10-04 09:40:56 +02:00
worker_threads.js worker: add public method for marking objects as untransferable 2020-06-25 08:33:29 -07:00
zlib.js lib: use remaining typed arrays from primordials 2020-10-07 13:44:21 +00:00