mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
3772cf56ae
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` (
|
||
---|---|---|
.. | ||
assert | ||
dns | ||
fs | ||
internal | ||
path | ||
stream | ||
timers | ||
util | ||
_http_agent.js | ||
_http_client.js | ||
_http_common.js | ||
_http_incoming.js | ||
_http_outgoing.js | ||
_http_server.js | ||
_stream_duplex.js | ||
_stream_passthrough.js | ||
_stream_readable.js | ||
_stream_transform.js | ||
_stream_wrap.js | ||
_stream_writable.js | ||
_tls_common.js | ||
_tls_wrap.js | ||
.eslintrc.yaml | ||
assert.js | ||
async_hooks.js | ||
buffer.js | ||
child_process.js | ||
cluster.js | ||
console.js | ||
constants.js | ||
crypto.js | ||
dgram.js | ||
diagnostics_channel.js | ||
dns.js | ||
domain.js | ||
events.js | ||
fs.js | ||
http2.js | ||
http.js | ||
https.js | ||
inspector.js | ||
module.js | ||
net.js | ||
os.js | ||
path.js | ||
perf_hooks.js | ||
process.js | ||
punycode.js | ||
querystring.js | ||
readline.js | ||
repl.js | ||
stream.js | ||
string_decoder.js | ||
sys.js | ||
timers.js | ||
tls.js | ||
trace_events.js | ||
tty.js | ||
url.js | ||
util.js | ||
v8.js | ||
vm.js | ||
wasi.js | ||
worker_threads.js | ||
zlib.js |