From 40fef4c21ccc09e628285d5fef3314586478d82c Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 29 Feb 2024 10:44:22 -0800 Subject: [PATCH] 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. --- lib/src/model/package_builder.dart | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/model/package_builder.dart b/lib/src/model/package_builder.dart index 5c2b2f3818..5629fced1b 100644 --- a/lib/src/model/package_builder.dart +++ b/lib/src/model/package_builder.dart @@ -233,10 +233,10 @@ class PubPackageBuilder implements PackageBuilder { // a set of files (starting with the ones passed into the function), resolve // them, add them to the package graph via `addLibrary`, and then discover // which additional files need to be processed in the next loop. This - // discovery depends on various options (TODO: which?), but the basic idea - // is to take a file we've just processed, and add all of the files which - // that file references via imports or exports, and add them to the set of - // files to be processed. + // discovery depends on various options (TODO: which?). The basic idea is + // to take a file we've just processed, and add all of the files which that + // file references (via imports, augmentation imports, exports, and parts), + // and add them to the set of files to be processed. // // This loop may execute a few times. We know to stop looping when we have // added zero new files to process. This is tracked with `filesInLastPass` @@ -251,9 +251,11 @@ class PubPackageBuilder implements PackageBuilder { if (!addingSpecials) { progressBarStart(files.length); } + // The set of files that are discovered while iterating in the below + // do-while loop, which are then added to `files`, as they are found. + var newFiles = {}; do { filesInLastPass = filesInCurrentPass; - var newFiles = {}; if (!addingSpecials) { progressBarUpdateTickCount(files.length); }