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

perf: Speed up getTargets #15228

Merged
merged 5 commits into from Dec 5, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/babel-helper-compilation-targets/src/index.ts
Expand Up @@ -173,13 +173,13 @@ function resolveTargets(queries: Browsers, env?: string): Targets {
const targetsCache = new LruCache(64);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need less than 64, since the targets are usually the same for every file (I believe that 8 would be enough). However it doesn't really matter, since 64 small allocations already has a very small memory footprint.


function resolveTargetsCached(queries: Browsers, env?: string): Targets {
const cacheKey = JSON.stringify(queries) + env;
let cached = targetsCache.get(cacheKey);
const cacheKey = typeof queries === "string" ? queries : queries.join() + env;
let cached = targetsCache.get(cacheKey) as Targets | undefined;
if (!cached) {
cached = resolveTargets(queries, env);
targetsCache.set(cacheKey, cached);
}
return cached;
return { ...cached };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like CI passed after this change, but I really don't know why I can't reproduce it.❓❓❓

}

type GetTargetsOption = {
Expand Down