Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cache): introduce standalone cache for find/parse #112

Merged
merged 12 commits into from
Aug 29, 2023

Conversation

dominikg
Copy link
Owner

used in findNative/parseNative as well.

Main motivation behind this is that the previous way to use findAll + tsconfigPaths could create a lot of extra work in huge projects, where ts files were contained in a small subtree.

Without having to traverse all of root and lazily caching all directories that have been traversed, this costs a little bit more memory, but less up front work.

Example for tsconfig in /a/b/c/tsconfig.json

const cache = new TSConfckCache(); 
const eConfig = await find('/a/b/c/d/e/foo.ts',{cache}); //  traverses e,d,c  to find the config and adds all to the cache separately
const dConfig = await find('/a/b/c/d/foo.ts',{cache}); // no traversal needed, cache hit
const fConfig = await find('/a/b/c/d/e/f/foo.ts',{cache});  // only traverse from f to e, then finds cache hit

(findNative caching is a little bit less effective as cache hits during traversal are impossible)

In a very large project with deep code trees and many directories, this can consume extra memory because all intermediate directories are added to the cache separately.

@dominikg
Copy link
Owner Author

Improved code to eagerly add Promises to cache instead of only setting results. This ensures that fs calls are minimized even with parallel async calls to find and parse. This can occur in vite when many files are passing through transformWithESbuild eg during devserver start.

@dominikg dominikg merged commit 3fe54bf into version-3 Aug 29, 2023
5 checks passed
@dominikg dominikg deleted the feat/lazy-cache branch August 29, 2023 20:31
@github-actions github-actions bot mentioned this pull request Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant