Correct looping bug in library discovery #3574
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current discover-libraries-in-a-loop code has a little bug in how libraries from new packages are tracked: Currently the loop is based on whether any new packages are discovered. So if a library from a new package is added in one loop, but the rest of the files which that library references (imports/exports) from the same package are found in the next loop, the package-tracking variables
current
andlastPass
don't catch this, and the new libraries from the same package are not processed.This bug is masked by the fact that we call
_parseLibraries
twice, once for elements-to-document, and once for "special classes" (Object, Incerceptor, Pragma, ...). I won't get into the whole idea of two_parseLibraries
calls here, as I'm just learning about the special libraries. In any case, the bug is hidden by this second call; those libraries that were left behind are now parsed/resolved in the second call, as they have been tracked with a field,_knownFiles
. The field is not reset between calls, so the missed libraries are found in the end. The bug does not manifest itself in the second call, because the only elements we wish to parse in that second call are in the Dart SDK.The bug does lead to performance degradation!! Or more specifically, the fact that
_knownFiles
is tracked in a field that isn't cleared between calls, causes a performance degradation. In that second call to_parseLibraries
, we re-resolve all known libraries!In this PR, I refactor
_knownFiles
away from being a field, and I track the_parseLibraries
loop with individual file sets, rather that package sets.This saves, on my M1 laptop, 10 seconds in documenting the googleapis package, and between 100 and 200 seconds in documenting Flutter (!!).
A few other notes:
_parseLibraries
had two function callback parameters which made the code hard for me to understand. I changed one to aaddingSpecials
bool parameter, and the function itself now controls how to filter added libraries, based on the bool.filterExcludes
parameter on_findFilesToDocumentInPackage
required; it was hard to reason at the call-sites what was being performed, when this parameter was optional.Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.