Skip to content

Commit

Permalink
perf: Improve performance of Quarkus deployment jar support
Browse files Browse the repository at this point in the history
Fixes #1143

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 16, 2023
1 parent 0ed538e commit 690f134
Show file tree
Hide file tree
Showing 33 changed files with 674 additions and 314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ public interface Listener {

private final Project project;

private final List<RunnableProgress> preprocessors;

public ClasspathResourceChangedManager(Project project) {
this.project = project;
this.preprocessors = new ArrayList<>();
// Send source files changed in debounce mode
this.resourceChangedNotifier = new ClasspathResourceChangedNotifier(project, preprocessors);
this.resourceChangedNotifier = new ClasspathResourceChangedNotifier(project);
listener = new ClasspathResourceChangedListener(this);
projectConnection = project.getMessageBus().connect();
// Track end of Java libraries update
Expand Down Expand Up @@ -105,13 +102,4 @@ Project getProject() {
ClasspathResourceChangedNotifier getResourceChangedNotifier() {
return resourceChangedNotifier;
}

/**
* Add a preprocessor to update classpatch when a library changed before sending the {@link Listener#librariesChanged()} event.
*
* @param preprocessor the preprocessor to add.
*/
public void addPreprocessor(RunnableProgress preprocessor) {
preprocessors.add(preprocessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
package com.redhat.devtools.intellij.lsp4mp4ij.classpath;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
Expand All @@ -27,10 +25,10 @@
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.HashSet;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

/**
* Source file change notifier with a debounce mode.
Expand All @@ -46,12 +44,10 @@ public class ClasspathResourceChangedNotifier implements Disposable {

private final Set<Pair<VirtualFile, Module>> sourceFiles;
private boolean librariesChanged;
private final List<RunnableProgress> processBeforeLibrariesChanged;
private boolean disposed;

public ClasspathResourceChangedNotifier(Project project, List<RunnableProgress> preprocessors) {
public ClasspathResourceChangedNotifier(Project project) {
this.project = project;
this.processBeforeLibrariesChanged = preprocessors;
sourceFiles = new HashSet<>();
}

Expand Down Expand Up @@ -107,11 +103,7 @@ private void notifyChanges() {
}
if (librariesChanged) {
// Java Libraries has changed
if (processBeforeLibrariesChanged.isEmpty() || ApplicationManager.getApplication().isUnitTestMode()) {
// No preprocessor or Test context, send directly the librariesChanged event.
for (var runnable : processBeforeLibrariesChanged) {
runnable.run(new EmptyProgressIndicator());
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
// Send the libraries changed event
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
librariesChanged = false;
Expand All @@ -125,9 +117,6 @@ public void run(@NotNull ProgressIndicator progressIndicator) {
// Execute preprocessor
progressIndicator.setIndeterminate(false);
progressIndicator.checkCanceled();
for (var runnable : processBeforeLibrariesChanged) {
runnable.run(progressIndicator);
}
} finally {
// Send the libraries changed event
project.getMessageBus().syncPublisher(ClasspathResourceChangedManager.TOPIC).librariesChanged();
Expand All @@ -152,7 +141,7 @@ public void dispose() {
this.disposed = true;
if (debounceTask != null) {
debounceTask.cancel();
debounceTask =null;
debounceTask = null;
}
if (debounceTimer != null) {
debounceTimer.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,19 @@ private static MicroProfileProjectInfo createInfo(Module module, ClasspathKind c
return info;
}

private SearchScope createSearchScope(Module module, List<MicroProfilePropertiesScope> scopes,
private SearchScope createSearchScope(@NotNull Module module, List<MicroProfilePropertiesScope> scopes,
boolean excludeTestCode) {
SearchScope searchScope = GlobalSearchScope.EMPTY_SCOPE;

if (MicroProfilePropertiesScope.isOnlySources(scopes)) {
return module.getModuleScope(!excludeTestCode);
}
SearchScope searchScope = GlobalSearchScope.moduleRuntimeScope(module, !excludeTestCode);
for (MicroProfilePropertiesScope scope : scopes) {
switch (scope) {
case sources:
searchScope = module != null ? searchScope.union(module.getModuleScope(!excludeTestCode)) : searchScope;
searchScope = searchScope.union(module.getModuleScope(!excludeTestCode));
break;
case dependencies:
searchScope = module != null ? searchScope.union(module.getModuleWithLibrariesScope()) : searchScope;
searchScope = searchScope.union(module.getModuleWithLibrariesScope());
break;
/*added missing default case */
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution,
* and is available at https://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package com.redhat.devtools.intellij.quarkus;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.impl.CoreProgressManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NlsContexts;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Progress indicator wrapper.
*/
public class ProgressIndicatorWrapper implements ProgressIndicator {

private final ProgressIndicator progressIndicator;

public ProgressIndicatorWrapper(ProgressIndicator progressIndicator) {
this.progressIndicator = progressIndicator;

}
public void start() {
progressIndicator.start();
}

public void stop() {
progressIndicator.stop();
}

public boolean isRunning() {
return progressIndicator.isRunning();
}

public void cancel() {
progressIndicator.cancel();
}

public boolean isCanceled() {
return progressIndicator.isCanceled();
}

public void setText(@NlsContexts.ProgressText String text) {
progressIndicator.setText(text);
}

@NlsContexts.ProgressText
public String getText() {
return progressIndicator.getText();
}

public void setText2(@NlsContexts.ProgressDetails String text) {
progressIndicator.setText2(text);
}

@NlsContexts.ProgressDetails
public String getText2() {
return progressIndicator.getText2();
}

public double getFraction() {
return progressIndicator.getFraction();
}

public void setFraction(double fraction) {
progressIndicator.setFraction(fraction);
}

public void pushState() {
progressIndicator.pushState();
}

public void popState() {
progressIndicator.popState();
}

public boolean isModal() {
return progressIndicator.isModal();
}

public @NotNull ModalityState getModalityState() {
return progressIndicator.getModalityState();
}

public void setModalityProgress(@Nullable ProgressIndicator modalityProgress) {
progressIndicator.setModalityProgress(modalityProgress);
}

public boolean isIndeterminate() {
return progressIndicator.isIndeterminate();
}

public void setIndeterminate(boolean indeterminate) {
progressIndicator.setIndeterminate(indeterminate);
}

public void checkCanceled() throws ProcessCanceledException {
progressIndicator.checkCanceled();
if (isCanceled() /*&& isCancelable()*/) {
Throwable trace = getCancellationTrace();
throw trace instanceof ProcessCanceledException ? (ProcessCanceledException)trace : new ProcessCanceledException(trace);
}
}

protected @Nullable Throwable getCancellationTrace() {
return this instanceof Disposable ? Disposer.getDisposalTrace((Disposable)this) : null;
}

public boolean isPopupWasShown() {
return progressIndicator.isPopupWasShown();
}

public boolean isShowing() {
return progressIndicator.isShowing();
}

}
Loading

0 comments on commit 690f134

Please sign in to comment.