Skip to content

Commit 40fef4c

Browse files
authored
In PackageBuilder._discoverLibraries, initialize newFiles outside loop. (#3695)
I noticed with print debugging that `addFilesReferencedBy` was being called way too many times for a given library. It turns out this is because it was being called on different Sets, when really it should mostly be operating on one Set. That one Set is `newFiles`. It was initialized in the do-while loop, but it can be initialized before the do-while loop. I checked the logic to make sure this change is a no-op. I also timed documenting flutter. This change seems to reduce the time-to-document by ~100 seconds, but that is only with one before and one after, so I promise nothing.
1 parent 2760d25 commit 40fef4c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/src/model/package_builder.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ class PubPackageBuilder implements PackageBuilder {
233233
// a set of files (starting with the ones passed into the function), resolve
234234
// them, add them to the package graph via `addLibrary`, and then discover
235235
// which additional files need to be processed in the next loop. This
236-
// discovery depends on various options (TODO: which?), but the basic idea
237-
// is to take a file we've just processed, and add all of the files which
238-
// that file references via imports or exports, and add them to the set of
239-
// files to be processed.
236+
// discovery depends on various options (TODO: which?). The basic idea is
237+
// to take a file we've just processed, and add all of the files which that
238+
// file references (via imports, augmentation imports, exports, and parts),
239+
// and add them to the set of files to be processed.
240240
//
241241
// This loop may execute a few times. We know to stop looping when we have
242242
// added zero new files to process. This is tracked with `filesInLastPass`
@@ -251,9 +251,11 @@ class PubPackageBuilder implements PackageBuilder {
251251
if (!addingSpecials) {
252252
progressBarStart(files.length);
253253
}
254+
// The set of files that are discovered while iterating in the below
255+
// do-while loop, which are then added to `files`, as they are found.
256+
var newFiles = <String>{};
254257
do {
255258
filesInLastPass = filesInCurrentPass;
256-
var newFiles = <String>{};
257259
if (!addingSpecials) {
258260
progressBarUpdateTickCount(files.length);
259261
}

0 commit comments

Comments
 (0)