You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Perf Regression - Excessive time spent in realpath in build mode #46204
Without having looked into it, my intuition is that the paths in the cache should already be in the desired form so that this realpath call should be unnecessary. Failing that, it might be appropriate to do an existence check before calling realpath.
Is realpath expensive when performed on non-existent paths? (Moreso than existence checks?) We definitely look up more paths now, since previously we weren't looking up these files during incremental mode at all (and so would never pick up changes to them) - and technically, there are a lot of possible locations for these files (all of which should be injected into our caches), since a package file could appear at any of the parent directories above a given file.
JFYI - one way to speed up the failure case is to freeze Error.stackTraceLimit to 0 for the duration of the fs call. Freezing this value is only supported in more recent versions of node, though - so may need some capabilities check if you want to use that
Wesley Wigham (@weswigham)Andrew Casey (@amcasey) initially it was intentional that we never watched package json files because build mode is suppose to only watch input files and use those time stamps for up to date ness ( we do not watch any module resolution stuff , if you want to do that , it’s watch mode on individual project as it’s too costly to do that when building solutions - list of projects ). Just fyi ..
It does, yes - it throws an ENOENT: no such file or directory on nonexistence. A lot of them definitely won't exist, too - in some cases we're watching locations like /package.json (yes - a package.json in the fs root) since if a file were to appear there, it'd affect resolution. If you think guarding the realpath call against use on non-existing paths will help in general, I've thrown up #46208 - if that's not good enough (since it does expand one fs call into two in the case where the file exists across all realpath calls), I also have #46209, which only avoids the realpath invocation on non-existing paths at this callsite.
JFYI - one way to speed up the failure case is to freeze Error.stackTraceLimit to 0 for the duration of the fs call. Freezing this value is only supported in more recent versions of node, though - so may need some capabilities check if you want to use that
We actually do this for statSync already - just not any other fs operations.
build mode is suppose to only watch input files and use those time stamps for up to date ness
package.json files are in the same vein as extended config files (which we do watch) - files not in the input list of source files, but affect program compilation in very meaningful ways.
Activity
amcasey commentedon Oct 4, 2021
FYI Wesley Wigham (@weswigham)
amcasey commentedon Oct 4, 2021
Without having looked into it, my intuition is that the paths in the cache should already be in the desired form so that this realpath call should be unnecessary. Failing that, it might be appropriate to do an existence check before calling realpath.
weswigham commentedon Oct 4, 2021
Is realpath expensive when performed on non-existent paths? (Moreso than existence checks?) We definitely look up more paths now, since previously we weren't looking up these files during incremental mode at all (and so would never pick up changes to them) - and technically, there are a lot of possible locations for these files (all of which should be injected into our caches), since a package file could appear at any of the parent directories above a given file.
amcasey commentedon Oct 4, 2021
Wesley Wigham (@weswigham) I seem to recall that it will throw if the path doesn't exist, but I may be thinking of a different IO call.
markjm commentedon Oct 4, 2021
JFYI - one way to speed up the failure case is to freeze Error.stackTraceLimit to 0 for the duration of the fs call. Freezing this value is only supported in more recent versions of node, though - so may need some capabilities check if you want to use that
jestjs/jest#11738
sheetalkamat commentedon Oct 4, 2021
Wesley Wigham (@weswigham) Andrew Casey (@amcasey) initially it was intentional that we never watched package json files because build mode is suppose to only watch input files and use those time stamps for up to date ness ( we do not watch any module resolution stuff , if you want to do that , it’s watch mode on individual project as it’s too costly to do that when building solutions - list of projects ). Just fyi ..
weswigham commentedon Oct 4, 2021
It does, yes - it throws an
ENOENT: no such file or directoryon nonexistence. A lot of them definitely won't exist, too - in some cases we're watching locations like/package.json(yes - apackage.jsonin the fs root) since if a file were to appear there, it'd affect resolution. If you think guarding therealpathcall against use on non-existing paths will help in general, I've thrown up #46208 - if that's not good enough (since it does expand one fs call into two in the case where the file exists across allrealpathcalls), I also have #46209, which only avoids therealpathinvocation on non-existing paths at this callsite.We actually do this for
statSyncalready - just not any otherfsoperations.weswigham commentedon Oct 4, 2021
package.jsonfiles are in the same vein as extended config files (which we do watch) - files not in the input list of source files, but affect program compilation in very meaningful ways.markjm commentedon Oct 4, 2021
Assume you are referring to here:
TypeScript/src/compiler/sys.ts
Line 1814 in 7fc1cb4
But this doesnt totally work as expected, as node will just set it back to Infinity (so long as stackTraceLimit isnt frozen)
https://github.com/nodejs/node/blob/b0a6ade3bd1be0bd2c60bf8d7a8652cdc75a4e59/lib/internal/errors.js#L460
To actually not capture the big trace, you need to set the value as non-writeable
weswigham commentedon Oct 4, 2021
👀 That's.... eck. Maybe we can just make more PRs for
throwIfNoEntry: falsefor more APIs in node.