Speedup startup

This commit is contained in:
Manfred Karrer 2014-09-09 16:30:50 +02:00
parent dcceb85669
commit 0403eb82e5
5 changed files with 37 additions and 63 deletions

View file

@ -129,7 +129,6 @@ public class BitSquare extends Application {
primaryStage.show(); primaryStage.show();
Profiler.printMsgWithTime("BitSquare: start finished");
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }

View file

@ -182,8 +182,6 @@ public class MainModel extends UIModel {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void onFacadesInitialised() { private void onFacadesInitialised() {
Profiler.printMsgWithTime("MainModel.onFacadesInitialised");
// TODO Check this: never called on regtest // TODO Check this: never called on regtest
// Consider to use version from Mike Hearn // Consider to use version from Mike Hearn
walletFacade.addDownloadListener(new WalletFacade.DownloadListener() { walletFacade.addDownloadListener(new WalletFacade.DownloadListener() {

View file

@ -38,13 +38,16 @@ public class Profiler {
public static void printMsgWithTime(String msg) { public static void printMsgWithTime(String msg) {
final long elapsed = threadStopwatch.get().elapsed(TimeUnit.MILLISECONDS); final long elapsed = threadStopwatch.get().elapsed(TimeUnit.MILLISECONDS);
log.trace("Msg: {} elapsed: {}ms / total time:[globalStopwatch: {}ms / threadStopwatch: {}ms / " + log.trace("\n\nCalled by: {} \nElapsed time: {}ms \nTotal time: {}ms\n\n",
msg, elapsed - last.get(), globalStopwatch.elapsed(TimeUnit.MILLISECONDS));
/* log.trace("Msg: {} elapsed: {}ms / total time:[globalStopwatch: {}ms / threadStopwatch: {}ms / " +
"currentTimeMillis: {}ms]", "currentTimeMillis: {}ms]",
msg, msg,
elapsed - last.get(), elapsed - last.get(),
globalStopwatch.elapsed(TimeUnit.MILLISECONDS), globalStopwatch.elapsed(TimeUnit.MILLISECONDS),
elapsed, elapsed,
System.currentTimeMillis() - lastCurrentTimeMillis); System.currentTimeMillis() - lastCurrentTimeMillis);*/
lastCurrentTimeMillis = System.currentTimeMillis(); lastCurrentTimeMillis = System.currentTimeMillis();
last.set(elapsed); last.set(elapsed);
} }

View file

@ -17,11 +17,11 @@
package io.bitsquare.gui.util; package io.bitsquare.gui.util;
import javafx.animation.Animation;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.KeyValue; import javafx.animation.KeyValue;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.scene.*; import javafx.scene.*;
import javafx.scene.effect.*; import javafx.scene.effect.*;
import javafx.scene.layout.*; import javafx.scene.layout.*;
@ -39,36 +39,37 @@ public class Transitions {
fadeIn(node, DURATION); fadeIn(node, DURATION);
} }
public static void fadeIn(Node node, int duration) { public static FadeTransition fadeIn(Node node, int duration) {
FadeTransition ft = new FadeTransition(Duration.millis(duration), node); FadeTransition fade = new FadeTransition(Duration.millis(duration), node);
ft.setFromValue(0.0); fade.setFromValue(node.getOpacity());
ft.setToValue(1.0); fade.setToValue(1.0);
ft.play(); fade.play();
return fade;
} }
public static Animation fadeOut(Node node) { public static FadeTransition fadeOut(Node node) {
return fadeOut(node, DURATION); return fadeOut(node, DURATION);
} }
public static Animation fadeOut(Node node, int duration) { public static FadeTransition fadeOut(Node node, int duration) {
FadeTransition ft = new FadeTransition(Duration.millis(duration), node); FadeTransition fade = new FadeTransition(Duration.millis(duration), node);
ft.setFromValue(node.getOpacity()); fade.setFromValue(node.getOpacity());
ft.setToValue(0.0); fade.setToValue(0.0);
ft.play(); fade.play();
return ft; return fade;
} }
public static Animation fadeOutAndRemove(Node node) { public static FadeTransition fadeOutAndRemove(Node node) {
return fadeOutAndRemove(node, DURATION); return fadeOutAndRemove(node, DURATION);
} }
public static Animation fadeOutAndRemove(Node node, int duration) { public static FadeTransition fadeOutAndRemove(Node node, int duration) {
Animation animation = fadeOut(node, duration); FadeTransition fade = fadeOut(node, duration);
animation.setOnFinished(actionEvent -> { fade.setOnFinished(actionEvent -> {
((Pane) (node.getParent())).getChildren().remove(node); ((Pane) (node.getParent())).getChildren().remove(node);
Profiler.printMsgWithTime("fadeOutAndRemove"); Profiler.printMsgWithTime("fadeOutAndRemove");
}); });
return animation; return fade;
} }
public static void blur(Node node) { public static void blur(Node node) {
@ -94,7 +95,8 @@ public class Transitions {
timeline.getKeyFrames().addAll(kf1); timeline.getKeyFrames().addAll(kf1);
} }
node.setEffect(blur); node.setEffect(blur);
if (removeNode) timeline.setOnFinished(actionEvent -> ((Pane) (node.getParent())).getChildren().remove(node)); if (removeNode) timeline.setOnFinished(actionEvent -> Platform.runLater(() -> ((Pane) (node.getParent()))
.getChildren().remove(node)));
timeline.play(); timeline.play();
return timeline; return timeline;
} }

View file

@ -38,7 +38,7 @@ import java.util.ResourceBundle;
import javax.inject.Inject; import javax.inject.Inject;
import javafx.application.Platform; import javafx.animation.Interpolator;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.geometry.Pos; import javafx.geometry.Pos;
@ -50,18 +50,12 @@ import javafx.scene.layout.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/**
* Holds the splash screen and the application views. It builds up all the views and initializes the facades.
* We use a sequence of Platform.runLater cascaded calls to make the startup more smooth, otherwise the rendering is
* frozen for too long. Pre-loading of views is not implemented yet, and after a quick test it seemed that it does not
* give much improvements.
*/
public class MainViewCB extends CachedCodeBehind<MainPM> { public class MainViewCB extends CachedCodeBehind<MainPM> {
private static final Logger log = LoggerFactory.getLogger(MainViewCB.class); private static final Logger log = LoggerFactory.getLogger(MainViewCB.class);
//TODO //TODO
private static MainViewCB instance; private static MainViewCB instance;
private boolean showNetworkSyncPaneRequested;
private VBox baseOverlayContainer; private VBox baseOverlayContainer;
private final ToggleGroup navButtonsGroup = new ToggleGroup(); private final ToggleGroup navButtonsGroup = new ToggleGroup();
private NavigationItem previousNavigationItem; private NavigationItem previousNavigationItem;
@ -215,40 +209,24 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void startup() { private void startup() {
buildBaseContainers();
}
private void buildBaseContainers() {
Profiler.printMsgWithTime("MainController.ViewBuilder.buildBaseContainers");
baseContentContainer = getBaseContentContainer(); baseContentContainer = getBaseContentContainer();
baseContentContainer.setOpacity(0);
baseOverlayContainer = getSplashScreen(); baseOverlayContainer = getSplashScreen();
((StackPane) root).getChildren().addAll(baseContentContainer, baseOverlayContainer); ((StackPane) root).getChildren().addAll(baseContentContainer, baseOverlayContainer);
Platform.runLater(this::buildContentView); onBaseContainersCreated();
} }
private void buildContentView() { private void onBaseContainersCreated() {
Profiler.printMsgWithTime("MainController.ViewBuilder.buildContentView"); Profiler.printMsgWithTime("MainController.onBaseContainersCreated");
menuBar = getMenuBar(); menuBar = getMenuBar();
contentScreen = getContentScreen(); contentScreen = getContentScreen();
addNetworkSyncPane();
if (showNetworkSyncPaneRequested)
addNetworkSyncPane();
baseContentContainer.setTop(menuBar); baseContentContainer.setTop(menuBar);
baseContentContainer.setCenter(contentScreen); baseContentContainer.setCenter(contentScreen);
Platform.runLater(this::onBaseContainersCreated);
}
// We need to wait until the backend is initialized as we need it for menu items like the balance field
private void onBaseContainersCreated() {
Profiler.printMsgWithTime("MainController.onBaseContainersCreated");
presentationModel.backendInited.addListener((ov, oldValue, newValue) -> { presentationModel.backendInited.addListener((ov, oldValue, newValue) -> {
if (newValue) if (newValue)
onBackendInited(); onBackendInited();
@ -264,12 +242,6 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
private void onMainNavigationAdded() { private void onMainNavigationAdded() {
Profiler.printMsgWithTime("MainController.ondMainNavigationAdded"); Profiler.printMsgWithTime("MainController.ondMainNavigationAdded");
triggerMainMenuButton(presentationModel.getSelectedNavigationItem());
Platform.runLater(this::onContentAdded);
}
private void onContentAdded() {
Profiler.printMsgWithTime("MainController.onContentAdded");
presentationModel.takeOfferRequested.addListener((ov, olaValue, newValue) -> { presentationModel.takeOfferRequested.addListener((ov, olaValue, newValue) -> {
final Button alertButton = new Button("", ImageUtil.getIconImageView(ImageUtil.MSG_ALERT)); final Button alertButton = new Button("", ImageUtil.getIconImageView(ImageUtil.MSG_ALERT));
@ -286,13 +258,13 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
AWTSystemTray.setAlert(); AWTSystemTray.setAlert();
}); });
Platform.runLater(this::fadeOutSplash); triggerMainMenuButton(presentationModel.getSelectedNavigationItem());
onContentAdded();
} }
private void fadeOutSplash() { private void onContentAdded() {
Profiler.printMsgWithTime("MainController.fadeOutSplash"); Profiler.printMsgWithTime("MainController.onContentAdded");
Transitions.blur(baseOverlayContainer, 700, false, true); Transitions.fadeOutAndRemove(baseOverlayContainer, 1500).setInterpolator(Interpolator.EASE_IN);
Transitions.fadeIn(baseContentContainer);
} }