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: early exit for pathIsInfolder (19% faster) #732

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
perf: getSequential avoid processing filePaths multiple times
Will now pre process filePaths and group them by their packagedirectory.
This prevents the same file being checked for inclusion in a directory
when it has already been included in a previous directory.
lukecotter committed Jan 21, 2025
commit 5d75b06716a91bad348d5948bf48f5662a043944
30 changes: 26 additions & 4 deletions src/shared/localComponentSetArray.ts
Original file line number Diff line number Diff line change
@@ -33,15 +33,37 @@ export const getGroupedFiles = (input: GroupedFileInput, byPackageDir = false):
(group) => group.deletes.length || group.nonDeletes.length
);

const getSequential = ({ packageDirs, nonDeletes, deletes }: GroupedFileInput): GroupedFile[] =>
packageDirs.map((pkgDir) => {
const getSequential = ({ packageDirs, nonDeletes, deletes }: GroupedFileInput): GroupedFile[] => {
const nonDeletesByPkgDir = groupByPkgDir(nonDeletes, packageDirs);
const deletesByPkgDir = groupByPkgDir(deletes, packageDirs);
return packageDirs.map((pkgDir) => {
const { name } = pkgDir;
return {
path: name,
nonDeletes: nonDeletes.filter(pathIsInFolder(name)),
deletes: deletes.filter(pathIsInFolder(name)),
nonDeletes: nonDeletesByPkgDir.get(name) ?? [],
deletes: deletesByPkgDir.get(name) ?? [],
};
});
};

const groupByPkgDir = (filePaths: string[], pkgDirs: NamedPackageDir[]): Map<string, string[]> => {
const groups = new Map<string, string[]>();
pkgDirs.forEach((pkgDir) => {
groups.set(pkgDir.name, []);
});

filePaths.forEach((filePath) => {
pkgDirs.forEach((pkgDir) => {
const { name } = pkgDir;
if (pathIsInFolder(name)(filePath)) {
groups.get(name)?.push(filePath);
return;
}
});
});

return groups;
};

const getNonSequential = ({
packageDirs,