Skip to content

Cache both exclude values and known parts #2347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2020
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
8 changes: 7 additions & 1 deletion lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,13 @@ class DartdocOptionContext extends DartdocOptionContextBase
String get examplePathPrefix =>
optionSet['examplePathPrefix'].valueAt(context);

List<String> get exclude => optionSet['exclude'].valueAt(context);
/// A memoized calculation of exclusions.
// TODO(srawlins): This memoization saved a lot of time in unit testing, but
// is the first value in this class to be memoized. Memoize others?
/*late final*/ List<String> _exclude;

List<String> get exclude =>
_exclude ??= optionSet['exclude'].valueAt(context);

List<String> get excludePackages =>
optionSet['excludePackages'].valueAt(context);
Expand Down
34 changes: 16 additions & 18 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class PubPackageBuilder implements PackageBuilder {
/// If [filePath] is not a library, returns null.
Future<DartDocResolvedLibrary> processLibrary(String filePath) async {
var name = filePath;
var directoryCurrentPath = config.resourceProvider.pathContext.current;
var directoryCurrentPath = resourceProvider.pathContext.current;

if (name.startsWith(directoryCurrentPath)) {
name = name.substring(directoryCurrentPath.length);
Expand Down Expand Up @@ -235,20 +235,15 @@ class PubPackageBuilder implements PackageBuilder {
return null;
}

Set<PackageMeta> _packageMetasForFiles(Iterable<String> files) {
var metas = <PackageMeta>{};
for (var filename in files) {
metas.add(packageMetaProvider.fromFilename(filename));
}
return metas;
}
Set<PackageMeta> _packageMetasForFiles(Iterable<String> files) => {
for (var filename in files) packageMetaProvider.fromFilename(filename),
};

/// Parse libraries with the analyzer and invoke a callback with the
/// Parses libraries with the analyzer and invokes [libraryAdder] with each
/// result.
///
/// Uses the [libraries] parameter to prevent calling
/// the callback more than once with the same [LibraryElement].
/// Adds [LibraryElement]s found to that parameter.
/// Uses [libraries] to prevent calling the callback more than once with the
/// same [LibraryElement]. Adds each [LibraryElement] found to [libraries].
Future<void> _parseLibraries(
void Function(DartDocResolvedLibrary) libraryAdder,
Set<LibraryElement> libraries,
Expand All @@ -257,17 +252,20 @@ class PubPackageBuilder implements PackageBuilder {
isLibraryIncluded ??= (_) => true;
var lastPass = <PackageMeta>{};
Set<PackageMeta> current;
var knownParts = <String>{};
do {
lastPass = _packageMetasForFiles(files);

// Be careful here not to accidentally stack up multiple
// DartDocResolvedLibrarys, as those eat our heap.
for (var f in files) {
// [DartDocResolvedLibrary]s, as those eat our heap.
for (var f in files.difference(knownParts)) {
logProgress(f);
var r = await processLibrary(f);
if (r != null &&
!libraries.contains(r.element) &&
isLibraryIncluded(r.element)) {
if (r == null) {
knownParts.add(f);
continue;
}
if (!libraries.contains(r.element) && isLibraryIncluded(r.element)) {
logDebug('parsing ${f}...');
libraryAdder(r);
libraries.add(r.element);
Expand All @@ -278,7 +276,7 @@ class PubPackageBuilder implements PackageBuilder {
await driver.discoverAvailableFiles();
files.addAll(driver.knownFiles);
files.addAll(_includeExternalsFrom(driver.knownFiles));
current = _packageMetasForFiles(files);
current = _packageMetasForFiles(files.difference(knownParts));
// To get canonicalization correct for non-locally documented packages
// (so we can generate the right hyperlinks), it's vital that we
// add all libraries in dependent packages. So if the analyzer
Expand Down