forked from salesforce/bazel-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 3
[performance] Import the large project #17
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,22 +17,25 @@ | |
| import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_REPO_BAZEL; | ||
| import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE; | ||
| import static com.salesforce.bazel.eclipse.core.BazelCoreSharedContstants.FILE_NAME_WORKSPACE_BAZEL; | ||
| import static com.salesforce.bazel.eclipse.core.model.BazelPackageInfo.queryForTargets; | ||
| import static java.lang.String.format; | ||
| import static java.nio.file.Files.isDirectory; | ||
| import static java.nio.file.Files.isRegularFile; | ||
| import static java.util.Objects.requireNonNull; | ||
| import static java.util.function.Predicate.not; | ||
| import static java.util.stream.Collectors.joining; | ||
| import static java.util.stream.Collectors.toList; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.eclipse.core.resources.IProject; | ||
| import org.eclipse.core.runtime.CoreException; | ||
| import org.eclipse.core.runtime.IPath; | ||
| import org.eclipse.core.runtime.Status; | ||
|
|
@@ -43,6 +46,8 @@ | |
| import com.salesforce.bazel.eclipse.core.projectview.BazelProjectView; | ||
| import com.salesforce.bazel.sdk.BazelVersion; | ||
| import com.salesforce.bazel.sdk.command.BazelBinary; | ||
| import com.salesforce.bazel.sdk.command.BazelQueryForTargetProtoCommand; | ||
| import com.salesforce.bazel.sdk.command.querylight.Target; | ||
| import com.salesforce.bazel.sdk.model.BazelLabel; | ||
|
|
||
| /** | ||
|
|
@@ -218,6 +223,11 @@ public boolean exists() { | |
| return isDirectory(path) && (findWorkspaceFile(path) != null); | ||
| } | ||
|
|
||
| public IProject findProject(BazelPackage bazelPackage) throws CoreException { | ||
| var info = bazelPackage.getBazelWorkspace().getInfo(); | ||
| return info.getProject(bazelPackage.getLabel()); | ||
| } | ||
|
|
||
| /** | ||
| * @return a collection of all targets loaded in memory | ||
| */ | ||
|
|
@@ -616,7 +626,7 @@ public void open(Collection<BazelPackage> bazelPackages) throws CoreException { | |
| } | ||
|
|
||
| // open all closed projects | ||
| var targetsByPackage = queryForTargets(this, closedPackages, getCommandExecutor()); | ||
| var targetsByPackage = queryForTargetsWithDependencies(this, closedPackages, getCommandExecutor()); | ||
| for (BazelPackage bazelPackage : closedPackages) { | ||
| if (bazelPackage.hasInfo()) { | ||
| continue; | ||
|
|
@@ -634,6 +644,11 @@ public void open(Collection<BazelPackage> bazelPackages) throws CoreException { | |
| LOG.warn("Package '{}' does not have a BUILD file, skipping", bazelPackage.getLabel()); | ||
| continue; | ||
| } | ||
| bazelPackage.setTargets(targets); | ||
| if (!bazelPackage.hasInfo()) { | ||
| // getting the info loads the package avoiding unnecessary double loads | ||
| bazelPackage.getInfo(); | ||
| } | ||
|
|
||
| // Create PackageInfo directly with the batched query results | ||
| var packageInfo = new BazelPackageInfo(buildFile, bazelPackage, targets); | ||
|
|
@@ -644,7 +659,77 @@ public void open(Collection<BazelPackage> bazelPackages) throws CoreException { | |
| } | ||
| } | ||
|
|
||
| public Map<BazelPackage, Map<String, Target>> queryForTargetsWithDependencies(BazelWorkspace bazelWorkspace, | ||
| Collection<BazelPackage> bazelPackages, BazelElementCommandExecutor bazelElementCommandExecutor) | ||
| throws CoreException { | ||
| // bazel query 'kind(rule, deps(//foo:all + //bar:all))"' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an interesting optimization for removing
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created #43 |
||
|
|
||
| if (bazelPackages.isEmpty()) { | ||
| return Collections.emptyMap(); | ||
| } | ||
| var workspaceRoot = bazelWorkspace.getLocation().toPath(); | ||
| var query = bazelPackages.stream() | ||
| .map(bazelPackage -> format("//%s:all", bazelPackage.getWorkspaceRelativePath())) | ||
| .collect(joining(" + ")); | ||
|
|
||
| Map<String, BazelPackage> bazelPackageByWorkspaceRelativePath = new HashMap<>(); | ||
| bazelPackages.stream() | ||
| .forEach(p -> bazelPackageByWorkspaceRelativePath.put(p.getWorkspaceRelativePath().toString(), p)); | ||
|
|
||
| query = "kind(rule, deps(" + query + "))"; | ||
| Map<BazelPackage, Map<String, Target>> result = new HashMap<>(); | ||
| LOG.debug("{}: querying Bazel for list of targets from: {}", bazelWorkspace, query); | ||
| var queryResult = bazelElementCommandExecutor.runQueryWithoutLock( | ||
| new BazelQueryForTargetProtoCommand( | ||
| workspaceRoot, | ||
| query, | ||
| true /* keep going */, | ||
| List.of("--noproto:locations", "--noproto:default_values", "--noimplicit_deps", "--notool_deps"), | ||
| format( | ||
| "Loading targets for %d %s", | ||
| bazelPackages.size(), | ||
| bazelPackages.size() == 1 ? "package" : "packages"))); | ||
| for (Target target : queryResult) { | ||
| if (!target.hasRule()) { | ||
| LOG.trace("{}: ignoring target: {}", bazelWorkspace, target); | ||
| System.out.println(); | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| BazelLabel.validateLabelPath(target.rule().name(), true); | ||
| } catch (Exception e) { | ||
| LOG.trace("{}: ignoring target: {}", bazelWorkspace, target); | ||
| continue; | ||
| } | ||
| LOG.trace("{}: found target: {}", bazelWorkspace, target); | ||
| var targetLabel = new BazelLabel(target.rule().name()); | ||
|
|
||
| var bazelPackage = bazelPackageByWorkspaceRelativePath.get(targetLabel.getPackagePath()); | ||
| if (bazelPackage == null) { | ||
| // LOG.debug("{}: ignoring target for unknown package: {}", bazelWorkspace, targetLabel); | ||
| // continue; | ||
| var packageLabel = targetLabel.getPackageLabel(); | ||
| if (bazelWorkspace.isRootedAtThisWorkspace(packageLabel)) { | ||
| bazelPackage = bazelWorkspace.getBazelPackage(packageLabel); | ||
| } | ||
| } | ||
| if (bazelPackage == null) { | ||
| LOG.debug("{}: ignoring target for unknown package: {}", bazelWorkspace, targetLabel); | ||
| continue; | ||
| } | ||
| if (!result.containsKey(bazelPackage)) { | ||
| result.put(bazelPackage, new HashMap<>()); | ||
| } | ||
|
|
||
| var targetName = targetLabel.getTargetName(); | ||
| result.get(bazelPackage).put(targetName, target); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| Path workspacePath() { | ||
| return root.toPath(); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eliminating the job removes transparency and visibility into the package. The job framework provides valuable insights in the Eclipse UI. I would rather like to see JDTLS improve here.
The second important thing provided by jobs framework is synchronization using
ISchedulingRule. It is important that at most ONE Bazel command is executed per workspace in general. The Bazel client prevents concurrent executions usually, which can lead to unexpected pauses/waits when multiple Bazel commands are executed by different threads. The job framework (again) helps visualizing this in the UI.