Improve list box performance by synchronizing less

This commit is contained in:
crschnick
2025-03-21 16:53:10 +00:00
parent 474d201708
commit b39c74b4ff

View File

@@ -262,25 +262,27 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
cache.keySet().removeIf(t -> !set.contains(t));
}
List<Region> newShown;
// Use copy to prevent concurrent modifications and to not synchronize to long
List<T> 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<Region> 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;