Skip to content

Commit

Permalink
perf: set priority for refresh and work threads
Browse files Browse the repository at this point in the history
refactor: use own executor service
  • Loading branch information
cmhulbert committed Sep 19, 2023
1 parent 6d1b2e1 commit 03eb093
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public OrthogonalViews(

final ForkJoinPool.ForkJoinWorkerThreadFactory factory = pool -> {
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
worker.setPriority(4);
worker.setName("render-thread-" + worker.getPoolIndex());
return worker;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.janelia.saalfeldlab.paintera.data.mask.MaskedSource;
import org.janelia.saalfeldlab.paintera.data.mask.SourceMask;
import org.janelia.saalfeldlab.paintera.data.mask.exception.MaskInUse;
import org.janelia.saalfeldlab.util.NamedThreadFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand All @@ -45,6 +46,8 @@
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;

Expand Down Expand Up @@ -156,6 +159,12 @@ public UtilityTask<Interval> fillViewerAt(final double currentViewerX, final dou
return fillMaskAt(maskPos, mask, fill, filter);
}

private ExecutorService floodFillExector = newFloodFillExecutor();

private ExecutorService newFloodFillExecutor() {
return Executors.newSingleThreadExecutor(new NamedThreadFactory("flood-fill-2d", false, 8));
}

@NotNull
private UtilityTask<Interval> fillMaskAt(Point maskPos, ViewerMask mask, Long fill, RandomAccessibleInterval<BoolType> filter) {

Expand All @@ -181,8 +190,11 @@ private UtilityTask<Interval> fillMaskAt(Point maskPos, ViewerMask mask, Long fi
});
});

floodFillTask.submit();
if (floodFillExector.isShutdown()) {
floodFillExector = newFloodFillExecutor();
}

floodFillTask.submit(floodFillExector);
refreshDuringFloodFill(floodFillTask).start();
return floodFillTask;
}
Expand Down Expand Up @@ -264,7 +276,7 @@ public static Thread refreshDuringFloodFill() {

public static Thread refreshDuringFloodFill(Task<Interval> task) {

return new Thread(() -> {
final Thread refreshScreenThread = new Thread(() -> {
while (task == null || !task.isDone()) {
try {
Thread.sleep(100);
Expand All @@ -283,6 +295,8 @@ public static Thread refreshDuringFloodFill(Task<Interval> task) {
task.cancel();
}
});
refreshScreenThread.setPriority(2);
return refreshScreenThread;
}

/**
Expand Down

0 comments on commit 03eb093

Please sign in to comment.