Skip to content

Commit

Permalink
Refactor Graph - Remove unnecessary earlyInverseDependencies
Browse files Browse the repository at this point in the history
Summary:
Since D51665495 made `Graph`'s internal state mutation synchronous, there's now no code path in which a module isn't either already available in `Graph.dependencies`, or immediately with a call to `_recursivelyCommitModule` - when an edge is being added. There's no longer any need to track `earlyInverseDependencies`.

Changelog: Internal

Reviewed By: motiz88

Differential Revision: D51938728

fbshipit-source-id: 35f3c8bc1b94a252189f80f02e32e060da461bba
  • Loading branch information
robhogan authored and facebook-github-bot committed Dec 22, 2023
1 parent 3aca493 commit 787f5f6
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions packages/metro/src/DeltaBundler/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ type Delta<T> = $ReadOnly<{
touched: Set<string>,
deleted: Set<string>,

// A place to temporarily track inverse dependencies for a module while it is
// being processed but has not been added to `graph.dependencies` yet.
earlyInverseDependencies: Map<string, CountingSet<string>>,

moduleData: Map<string, ModuleData<T>>,
}>;

Expand Down Expand Up @@ -210,7 +206,6 @@ export class Graph<T = MixedOutput> {
added: new Set<string>(),
touched: new Set<string>(),
deleted: new Set<string>(),
earlyInverseDependencies: new Map<string, CountingSet<string>>(),
moduleData,
};

Expand Down Expand Up @@ -278,7 +273,6 @@ export class Graph<T = MixedOutput> {
added: new Set<string>(),
touched: new Set<string>(),
deleted: new Set<string>(),
earlyInverseDependencies: new Map<string, CountingSet<string>>(),
moduleData,
};

Expand Down Expand Up @@ -313,8 +307,7 @@ export class Graph<T = MixedOutput> {

const nextModule = {
...(previousModule ?? {
inverseDependencies:
delta.earlyInverseDependencies.get(path) ?? new CountingSet(),
inverseDependencies: new CountingSet(),
path,
}),
...transformResult,
Expand Down Expand Up @@ -430,26 +423,12 @@ export class Graph<T = MixedOutput> {
this._incrementImportBundleReference(dependency, parentModule);
} else {
if (!module) {
// Add a new node to the graph.
const earlyInverseDependencies =
delta.earlyInverseDependencies.get(path);
if (earlyInverseDependencies) {
// This module is being transformed at the moment in parallel, so we
// should only mark its parent as an inverse dependency.
earlyInverseDependencies.add(parentModule.path);
} else {
delta.earlyInverseDependencies.set(path, new CountingSet());

module = this._recursivelyCommitModule(path, delta, options);

this.dependencies.set(module.path, module);
}
}
if (module) {
// We either added a new node to the graph, or we're updating an existing one.
module.inverseDependencies.add(parentModule.path);
this._markModuleInUse(module);
module = this._recursivelyCommitModule(path, delta, options);
}

// We either added a new node to the graph, or we're updating an existing one.
module.inverseDependencies.add(parentModule.path);
this._markModuleInUse(module);
}

// Always update the parent's dependency map.
Expand Down Expand Up @@ -690,7 +669,6 @@ export class Graph<T = MixedOutput> {
// Clean up all the state associated with this module in order to correctly
// re-add it if we encounter it again.
this.dependencies.delete(module.path);
delta.earlyInverseDependencies.delete(module.path);
this.#gc.possibleCycleRoots.delete(module.path);
this.#gc.color.delete(module.path);
this.#resolvedContexts.delete(module.path);
Expand Down

0 comments on commit 787f5f6

Please sign in to comment.