module: cache nearest parent package.json per directory · nodejs/node@43757d0 · GitHub
Skip to content

Commit 43757d0

Browse files
codebytereaduh95
authored andcommitted
module: cache nearest parent package.json per directory
getNearestParentPackageJSON() memoized its answer per file, so every module loaded still made one native call, and TraverseParent() builds several std::filesystem::path temporaries per directory level and serializes the whole package.json, which the JS side then usually discarded because it already had that package.json deserialized. The native traversal starts at the directory of the given path, so the answer only depends on that directory: key the memo by it (following NormalizePath()'s trailing-separator rule), so that all modules in a directory share one native call. When the permission model is enabled the traversal also depends on the read permissions in effect at call time, so that configuration keeps the per-file cache. Loading a 1000-module tree spread over ~240 directories goes from 1000 to 236 native calls. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65326 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com>
1 parent 77fedbd commit 43757d0

2 files changed

Lines changed: 106 additions & 19 deletions

File tree

lib/internal/modules/package_json_reader.js

Lines changed: 49 additions & 19 deletions
Lines changed: 57 additions & 0 deletions

0 commit comments

Comments
 (0)