From b39c74b4ff5caefcf8078d8ebdc9346987330f3e Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 21 Mar 2025 16:53:10 +0000 Subject: [PATCH] Improve list box performance by synchronizing less --- .../xpipe/app/comp/base/ListBoxViewComp.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java index 5b992ddcb..1595117ee 100644 --- a/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java +++ b/app/src/main/java/io/xpipe/app/comp/base/ListBoxViewComp.java @@ -262,25 +262,27 @@ public class ListBoxViewComp extends Comp> { cache.keySet().removeIf(t -> !set.contains(t)); } - List newShown; + // Use copy to prevent concurrent modifications and to not synchronize to long + List shownCopy; synchronized (shown) { - newShown = shown.stream().map(v -> { - if (!cache.containsKey(v)) { - var comp = compFunction.apply(v); - if (comp != null) { - var r = comp.createRegion(); - if (visibilityControl) { - r.setVisible(false); - } - cache.put(v, r); - } else { - cache.put(v, null); - } - } - - return cache.get(v); - }).filter(region -> region != null).toList(); + shownCopy = new ArrayList<>(shown); } + List newShown = shownCopy.stream().map(v -> { + if (!cache.containsKey(v)) { + var comp = compFunction.apply(v); + if (comp != null) { + var r = comp.createRegion(); + if (visibilityControl) { + r.setVisible(false); + } + cache.put(v, r); + } else { + cache.put(v, null); + } + } + + return cache.get(v); + }).filter(region -> region != null).toList(); if (listView.getChildren().equals(newShown)) { return;