DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.36k stars 29 forks source link

Faster and robust config searching via `readdir` instead of `opendir` #1183

Closed edemaine closed 5 months ago

edemaine commented 5 months ago

Performance: fs.opendir stats every file in a directory, I believe. We only need to stat names that match .config or civetconfig.*. I've restructured to use fs.readdir which just gets the listing, and only stat files we care about. On some file systems, this can be orders of magnitudes faster.

Also, stat can throw, and we can't really catch that from fs.opendir. MIT's UNIX machines use AFS (Andrew File System) which is ... particular. The parent directory of my home directory has 500 subdirectories, and some of them fail to stat. In particular, every time I run the Civet CLI (without --no-config) I get this error:

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: ENODEV: no such device, lstat 'xxx'] {
  errno: -19,
  code: 'ENODEV',
  syscall: 'lstat',
  path: 'xxx'
}

(where xxx is the parent of my home directory)

With this PR, I can finally run the CLI on these machines without --no-config 😄