Bug 576521 - Avoid UI freezes due to slow Debug view Only proceed maximum 100 model changes of the Debug view in one batch and then give other UI tasks a chance to proceed in between. This should avoid long UI freezes while updating the JFace tree in case debuggee application generates many model changes that need to be processed in the Debug view Change-Id: I0a9ef6764e41f88ace3bae57ed40adaad9a8c368 Signed-off-by: Joerg Kubitz <jkubitz-eclipse@gmx.de> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.debug/+/186381 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java index 4ed94c5..c00ae9f 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelContentProvider.java
@@ -401,6 +401,9 @@ private class DelayedDoModelChangedJob extends WorkbenchJob { + // limit batch size to avoid freezing the UI. + private static final int MAX_BATCH_SIZE = 100; + // queue of submitted deltas to process private final List<Object> fQueue = new ArrayList<>(); private boolean shutdown; @@ -418,8 +421,18 @@ if (shutdown || fQueue.isEmpty()) { return Status.OK_STATUS; } - currentBatch = new ArrayList<>(fQueue); - fQueue.clear(); + fQueue.removeIf(o -> { + if (currentBatch.size() < MAX_BATCH_SIZE) { + currentBatch.add(o); + return true; + } + return false; + }); + if (!fQueue.isEmpty()) { + // There is work left. + // Give other UI tasks chance to work instead of freezing UI + schedule(); + } } if (DebugUIPlugin.DEBUG_CONTENT_PROVIDER) { DebugUIPlugin.trace("Delayed batch size: " + currentBatch.size()); //$NON-NLS-1$