Skip to content

Commit

Permalink
Merge pull request #42278 from Thevakumar-Luheerathan/fix-ballerina-l…
Browse files Browse the repository at this point in the history
…ang-iss-42261

Fix higher CPU usage during package resolution
  • Loading branch information
azinneera authored Mar 5, 2024
2 parents 2752ae1 + 46192fe commit ff343cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private Collection<ModuleDescriptor> getAllDependants(ModuleDescriptor updatedMo
CompilationOptions offlineCompOptions = CompilationOptions.builder().setOffline(true).build();
offlineCompOptions = offlineCompOptions.acceptTheirs(project.currentPackage().compilationOptions());
// this will build the dependency graph if it is not built yet
packageInstance.getResolution(offlineCompOptions);
packageInstance.packageContext().getResolution(offlineCompOptions, true);
return getAllDependants(updatedModuleDescriptor, new HashSet<>(), new HashSet<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public PackageResolution getResolution(ResolutionOptions resolutionOptions) {
boolean sticky = resolutionOptions.sticky();
CompilationOptions newCompOptions = CompilationOptions.builder().setOffline(offline).setSticky(sticky).build();
newCompOptions = newCompOptions.acceptTheirs(project.currentPackage().compilationOptions());
return getResolution(newCompOptions);
return this.packageContext.getResolution(newCompOptions, true);
}

private static class ModuleIterable implements Iterable {
Expand Down Expand Up @@ -633,8 +633,8 @@ private Package createNewPackage() {

CompilationOptions offlineCompOptions = CompilationOptions.builder().setOffline(true).build();
offlineCompOptions = offlineCompOptions.acceptTheirs(project.currentPackage().compilationOptions());
DependencyGraph<ResolvedPackageDependency> newDepGraph = this.project.currentPackage()
.getResolution(offlineCompOptions).dependencyGraph();
DependencyGraph<ResolvedPackageDependency> newDepGraph = this.project.currentPackage().packageContext()
.getResolution(offlineCompOptions, true).dependencyGraph();
cleanPackageCache(this.dependencyGraph, newDepGraph);
return this.project.currentPackage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ PackageResolution getResolution(CompilationOptions compilationOptions) {
packageResolution = PackageResolution.from(this, compilationOptions);
return packageResolution;
}

PackageResolution getResolution(CompilationOptions compilationOptions, boolean isCacheEnabled) {
if (!isCacheEnabled || packageResolution == null) {
packageResolution = PackageResolution.from(this, compilationOptions);
}
return packageResolution;
}

Collection<PackageDependency> packageDependencies() {
return packageDependencies;
}
Expand Down

0 comments on commit ff343cd

Please sign in to comment.