Skip to content

Commit

Permalink
Merge pull request #546 from saalfeldlab/wip/perf/memory
Browse files Browse the repository at this point in the history
Wip/perf/memory
  • Loading branch information
cmhulbert authored Aug 13, 2024
2 parents 2052693 + b077145 commit c50b9a4
Show file tree
Hide file tree
Showing 46 changed files with 1,105 additions and 1,232 deletions.
32 changes: 21 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>paintera</artifactId>
<version>1.3.5-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>

<name>Paintera</name>
<description>New Era Painting and annotation tool</description>
Expand Down Expand Up @@ -58,16 +58,18 @@

<!-- JavaFx Version-->
<javafx.version>22.0.1</javafx.version>
<saalfx.version>2.0.0</saalfx.version>
<saalfx.version>2.1.0</saalfx.version>
<testfx.version>4.0.16-alpha</testfx.version>

<alphanumeric-comparator.version>1.4.1</alphanumeric-comparator.version>
<dokka.version>1.4.30</dokka.version>


<main-class>org.janelia.saalfeldlab.paintera.Paintera</main-class>
<app.name>Paintera</app.name>
<app.package>paintera</app.package>
<app.version>1.3.4</app.version>
<app.version>1.4.0</app.version>

<jvm.modules>javafx.base,javafx.controls,javafx.fxml,javafx.media,javafx.swing,javafx.web,javafx.graphics,java.naming,java.management,java.sql</jvm.modules>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<windows.upgrade.uuid>f918b6f9-8685-4b50-9fbd-9be7a1209249</windows.upgrade.uuid>
Expand All @@ -79,8 +81,7 @@
<n5-aws-s3.version>4.2.1</n5-aws-s3.version>
<n5-google-cloud>4.1.1</n5-google-cloud>
<n5-zarr.version>1.3.5</n5-zarr.version>

<imglib2-label-multisets.version>0.14.0</imglib2-label-multisets.version>
<imglib2-label-multisets.version>0.15.0</imglib2-label-multisets.version>

<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<enforcer.skip>true</enforcer.skip>
Expand Down Expand Up @@ -332,15 +333,14 @@
<artifactId>scripting-groovy</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
Expand Down Expand Up @@ -687,7 +687,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<argLine>-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw</argLine>
<argLine>-Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw --enable-preview</argLine>
</configuration>
</plugin>
</plugins>
Expand All @@ -707,6 +707,9 @@
<annotationProcessors>
<annotationProcessor>org.scijava.annotations.AnnotationProcessor</annotationProcessor>
</annotationProcessors>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -910,6 +913,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<javacOptions>
<javacOption>--enable-preview</javacOption>
</javacOptions>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -999,9 +1012,6 @@
<phase>none</phase>
</execution>
</executions>
<configuration>
<jvmTarget>11</jvmTarget>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public ViewerPanelFX(
heightProperty().subscribe(height -> renderUnit.setDimensions((long)getWidth(), height.longValue()));

visibleProperty().subscribe(visible -> {
if (!visible)
if (visible)
renderUnit.setDimensions((long)getWidth(), (long)getHeight());
else
renderUnit.stopRendering();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ public boolean isVisible() {

public synchronized int getBestMipMapLevel() {

final var currentSource = Paintera.getPaintera().getBaseView().sourceInfo().currentSourceProperty().get();
return getBestMipMapLevel(Paintera.getPaintera().getBaseView().sourceInfo().currentSourceProperty().get());
}

public int getBestMipMapLevel(Source<?> source) {

final AffineTransform3D screenScaleTransform = new AffineTransform3D();
viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform);
return getBestMipMapLevel(screenScaleTransform, currentSource);
return getBestMipMapLevel(screenScaleTransform, source);
}

public synchronized ViewerState copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public final class PainterThreadFx extends Thread {

private boolean isRunning;

private long lastUpdate = -1;
private long targetFrameRateMs = 1000 / 60;

public PainterThreadFx(PainterThreadFx.Paintable paintable) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,23 @@ public abstract class RenderUnit implements PainterThreadFx.Paintable {
protected PainterThreadFx painterThread;
protected boolean useVolatileIfAvailable = true;

public RenderUnit(final ThreadGroup threadGroup, final Function<Source<?>, Interpolation> interpolation, final AccumulateProjectorFactory<ARGBType> accumulateProjectorFactory, final CacheControl cacheControl, final long targetRenderNanos, final TaskExecutor renderingTaskExecutor) {
public RenderUnit(
final ThreadGroup threadGroup,
final Function<Source<?>, Interpolation> interpolation,
final AccumulateProjectorFactory<ARGBType> accumulateProjectorFactory,
final CacheControl cacheControl,
final long targetRenderNanos,
final TaskExecutor renderingTaskExecutor,
final boolean useVolatileIfAvailable
) {

this.threadGroup = threadGroup;
this.interpolation = interpolation;
this.accumulateProjectorFactory = accumulateProjectorFactory;
this.cacheControl = cacheControl;
this.targetRenderNanos = targetRenderNanos;
this.renderingTaskExecutor = renderingTaskExecutor;
this.useVolatileIfAvailable = useVolatileIfAvailable;
}

public void stopRendering() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -147,12 +148,12 @@ public OrthogonalViews(
final Function<Source<?>, Interpolation> interpolation) {

this.manager = manager;

final var count = new AtomicInteger();
final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
worker.setDaemon(true);
worker.setPriority(4);
worker.setName("render-thread-" + worker.getPoolIndex());
worker.setName("render-thread-" + count.getAndIncrement());
return worker;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Contains all the things necessary to build a Paintera UI, most importantly:
Expand Down Expand Up @@ -123,15 +124,16 @@ public class PainteraBaseView {
private final ExecutorService propagationQueue;

{
final AtomicInteger count = new AtomicInteger();
final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
worker.setDaemon(true);
worker.setPriority(4);
worker.setName("propagation-queue-" + worker.getPoolIndex());
worker.setName("propagation-queue-" + count.getAndIncrement());
return worker;
};

propagationQueue = new ForkJoinPool(Math.max(1, Runtime.getRuntime().availableProcessors() - 2), factory, null, false);
propagationQueue = new ForkJoinPool(Math.max(1, Runtime.getRuntime().availableProcessors() - 2), factory, (thread, throwable) -> throwable.printStackTrace(), false);

}

Expand Down Expand Up @@ -382,7 +384,7 @@ public <D extends RealType<D> & NativeType<D>, T extends AbstractVolatileNativeR
final String name) {

final ConnectomicsRawState<D, T> state = new ConnectomicsRawState<D, T>(
new RaiBackendRaw<D, T>(data, resolution, offset, "test"),
new RaiBackendRaw<>(data, resolution, offset, "test"),
getQueue(),
getQueue().getNumPriorities() - 1,
name
Expand Down Expand Up @@ -486,7 +488,7 @@ public <D extends RealType<D> & NativeType<D>, T extends AbstractVolatileNativeR
final String name,
LabelBlockLookup labelBlockLookup) {

return this.addConnectomicsLabelSource(
return addConnectomicsLabelSource(
new RandomAccessibleInterval[]{data},
new double[][]{resolution},
new double[][]{offset},
Expand Down Expand Up @@ -560,7 +562,7 @@ public static int reasonableNumFetcherThreads() {
*/
public ExecutorService getMeshManagerExecutorService() {

return this.meshManagerExecutorService;
return meshManagerExecutorService;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.janelia.saalfeldlab.paintera.control;

import bdv.viewer.Source;
import org.janelia.saalfeldlab.bdv.fx.viewer.ViewerPanelFX;
import bdv.viewer.TransformListener;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -35,16 +36,19 @@ public class OrthoViewCoordinateDisplayListener {

private final ObjectProperty<OrthogonalViews.ViewerAndTransforms> activeViewerProperty = new SimpleObjectProperty<>();

private final ObservableValue<Source<?>> currentSource;

public OrthoViewCoordinateDisplayListener(
final Consumer<RealPoint> submitViewerCoordinate,
final Consumer<RealPoint> submitWorldCoordinate,
final Consumer<RealPoint> submitSourceCoordinate
final Consumer<RealPoint> submitSourceCoordinate,
final ObservableValue<Source<?>> currentSource
) {

super();
this.submitViewerCoordinate = submitViewerCoordinate;
this.submitWorldCoordinate = submitWorldCoordinate;
this.submitSourceCoordinate = submitSourceCoordinate;
this.currentSource = currentSource;
activeViewerProperty.addListener((obs, exiting, entering) -> {
if (Objects.nonNull(exiting)) {
removeHandlers(exiting.viewer());
Expand All @@ -58,8 +62,7 @@ public OrthoViewCoordinateDisplayListener(
public void addHandlers(ViewerPanelFX viewer) {

if (!this.listeners.containsKey(viewer)) {
final CoordinateDisplayListener coordinateListener = new CoordinateDisplayListener(viewer, submitViewerCoordinate, submitWorldCoordinate,
submitSourceCoordinate);
final CoordinateDisplayListener coordinateListener = new CoordinateDisplayListener(viewer, currentSource, submitViewerCoordinate, submitWorldCoordinate, submitSourceCoordinate);
final var coordinateUpdate = painteraActionSet("coordinate update", null, actionSet -> {
actionSet.addMouseAction(MouseEvent.MOUSE_MOVED, action -> {
action.setConsume(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class OrthogonalViewsValueDisplayListener {

private final Map<ViewerPanelFX, ValueDisplayListener> listeners = new HashMap<>();
private final Map<ViewerPanelFX, ValueDisplayListener<?>> listeners = new HashMap<>();

private final Consumer<String> submitValue;

Expand Down Expand Up @@ -49,21 +49,24 @@ public OrthogonalViewsValueDisplayListener(

public void addHandlers(ViewerPanelFX viewer) {

if (!this.listeners.containsKey(viewer))
this.listeners.put(viewer, new ValueDisplayListener(viewer, currentSource, interpolation, submitValue));
viewer.getDisplay().addEventFilter(MouseEvent.MOUSE_MOVED, this.listeners.get(viewer));
viewer.addTransformListener(this.listeners.get(viewer));
listeners.putIfAbsent(viewer, new ValueDisplayListener<>(viewer, currentSource, interpolation, submitValue));

viewer.getDisplay().addEventFilter(MouseEvent.MOUSE_MOVED, listeners.get(viewer));
viewer.addTransformListener(listeners.get(viewer));
}

public void removeHandlers(ViewerPanelFX viewer) {

viewer.getDisplay().removeEventHandler(MouseEvent.MOUSE_MOVED, this.listeners.get(viewer));
viewer.removeTransformListener(this.listeners.get(viewer));
listeners.computeIfPresent(viewer, (key, vdl) -> {
viewer.getDisplay().removeEventHandler(MouseEvent.MOUSE_MOVED, vdl);
viewer.removeTransformListener(vdl);
return null;
});
submitValue.accept("");
}

public void bindActiveViewer(ObservableValue<OrthogonalViews.ViewerAndTransforms> activeViewerObservable) {
/* Binding would be neater here, but inexplicably, doesn't work? */
activeViewerObservable.addListener((obs, oldv, newv) -> activeViewerProperty.set(newv));
activeViewerObservable.subscribe(activeViewerProperty::set);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public synchronized void persist() throws UnableToPersist {
}

@Override
public synchronized long getSegment(final long fragmentId) {
public long getSegment(final long fragmentId) {

final long id;
final long segmentId = fragmentToSegmentMap.get(fragmentId);
Expand Down
Loading

0 comments on commit c50b9a4

Please sign in to comment.