Skip to content

Commit

Permalink
perf(enrich/reachable): do even less when there's no reachable rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Jan 6, 2025
1 parent d2550e4 commit eb7bf8a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/enrich/derive/reachable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,15 @@ function addReachabilityToGraph(pGraph, pIndexedGraph, pReachableRule) {

export default function deriveReachables(pGraph, pRuleSet) {
const lReachableRules = pRuleSet ? getReachableRules(pRuleSet) : [];
const lIndexedGraph =
lReachableRules.length > 0 ? new IndexedModuleGraph(pGraph) : {};

return lReachableRules.reduce(
(pReturnGraph, pRule) =>
addReachabilityToGraph(pReturnGraph, lIndexedGraph, pRule),
structuredClone(pGraph),
);
if (lReachableRules.length > 0) {
const lIndexedGraph = new IndexedModuleGraph(pGraph);

return lReachableRules.reduce(
(pReturnGraph, pRule) =>
addReachabilityToGraph(pReturnGraph, lIndexedGraph, pRule),
structuredClone(pGraph),
);
}
return pGraph;
}

0 comments on commit eb7bf8a

Please sign in to comment.