Skip to content

Don't search the file system for node: modules #48431

Open

Description

@amcasey

Running tsc on this .ts file results in a number of unnecessary file system accesses

import * as fs from "node:fs";

fs.chmod; // Prevent it from being unused

On my box, it searches

/home/amcasey/repos/perf_utils/node_modules/node:fs
/home/amcasey/repos/perf_utils/node_modules/node:fs.ts
/home/amcasey/repos/perf_utils/node_modules/node:fs.tsx
/home/amcasey/repos/perf_utils/node_modules/node:fs.d.ts
/home/amcasey/repos/perf_utils/node_modules/@types/node:fs
/home/amcasey/repos/perf_utils/node_modules/@types/node:fs.d.ts
/home/amcasey/repos/perf_utils/node_modules/node:fs.js
/home/amcasey/repos/perf_utils/node_modules/node:fs.jsx

Since file system access has been a performance bottleneck in the past, it would be nice to avoid these checks.

(Caveat: Linux actually allows colons in file names, so this would technically change the resolution behavior. I can't tell whether it's by-design or not that it might find node:fs.ts on disk.)

Activity

  1. amcasey commented on Mar 26, 2022

    @amcasey
    MemberAuthor

    Wesley Wigham (@weswigham) has thoughts (including that Ron Buckton (@rbuckton) is probably the expert)

  2. amcasey commented on Mar 26, 2022

    @amcasey
    MemberAuthor

    I also tried import fs = require("node:fs") - it worked the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions