Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.10.3-wip

- Performance: improve scalability with the number of library cycles, making
builds much faster for some large codebases.
- Bug fix: fix crash when you run `dart run build_runner build` in a
subdirectory of a package.
- Bug fix: in a workspace, generate for transitive dependencies of the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,21 @@ class LibraryCycleGraphLoader {
///
/// A [_graphs] entry will be created for each ID in [newCycles].
void _buildGraphs(int phase, {required List<LibraryCycle> newCycles}) {
// Build lookup from ID to [LibraryCycle] including new and existing cycles.

Choose a reason for hiding this comment

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

Am I reading this right, that this boils down to not pre-populating the map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly :)

final existingCycles = <LibraryCycle>[];
for (final phasedCycle in _cycles.values) {
if (phasedCycle.isExpiredAt(phase: phase)) continue;
existingCycles.add(phasedCycle.valueAt(phase: phase));
}
// Cycles by ID at the current phase.
final cycleById = <AssetId, LibraryCycle>{};
for (final cycle in existingCycles) {
for (final id in cycle.ids) {
cycleById[id] = cycle;
}
}
for (final cycle in newCycles) {
for (final id in cycle.ids) {
cycleById[id] = cycle;
}
}

/// Lookups up [id] in [cycleById], falling back to [_cycles] if it's not
/// present.
LibraryCycle lookupLibraryCycle(AssetId id) =>
cycleById.putIfAbsent(id, () {
return _cycles[id]!.valueAt(phase: phase);
});

// Create the graph for each cycle in [newCycles].
for (final root in newCycles) {
final graph = LibraryCycleGraphBuilder()..root.replace(root);
Expand All @@ -379,7 +376,7 @@ class LibraryCycleGraphLoader {
for (final id in root.ids) {
final assetDeps = _assetDeps[id]!.valueAt(phase: phase);
for (final dep in assetDeps.deps) {
final depCycle = cycleById[dep]!;
final depCycle = lookupLibraryCycle(dep);
if (identical(depCycle, root)) continue;
if (alreadyAddedChildren.add(depCycle)) {
final childGraph = _graphs[dep]!.expiringValueAt(phase: phase);
Expand Down