From 379f62967b20cd1bdb21805703f90ff965cd16f7 Mon Sep 17 00:00:00 2001 From: "Liana.Bakradze" Date: Wed, 19 Apr 2017 18:56:26 +0300 Subject: [PATCH] do not execute all the requests to debugger while scrolling (PY-14960) --- .../debugger/array/AsyncArrayTableModel.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java b/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java index 43090ced44de..3879ac4d7f3f 100644 --- a/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java +++ b/python/src/com/jetbrains/python/debugger/array/AsyncArrayTableModel.java @@ -23,6 +23,8 @@ import com.google.common.util.concurrent.ListenableFutureTask; import com.intellij.openapi.util.Pair; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.ui.UIUtil; +import com.intellij.util.ui.update.MergingUpdateQueue; +import com.intellij.util.ui.update.Update; import com.jetbrains.python.debugger.ArrayChunk; import com.jetbrains.python.debugger.ArrayChunkBuilder; import com.jetbrains.python.debugger.PyDebugValue; @@ -48,6 +50,7 @@ public class AsyncArrayTableModel extends AbstractTableModel { private final ExecutorService myExecutorService = ConcurrencyUtil.newSingleThreadExecutor("Python async table"); + private final MergingUpdateQueue myQueue = new MergingUpdateQueue("Python async table queue", 100, true, null); private PyDebugValue myDebugValue; private final DataViewStrategy myStrategy; @@ -56,17 +59,13 @@ public class AsyncArrayTableModel extends AbstractTableModel { @Override public ListenableFuture load(@NotNull final Pair key) throws Exception { - ListenableFutureTask task = ListenableFutureTask.create(() -> { + return ListenableFutureTask.create(() -> { ArrayChunk chunk = myDebugValue.getFrameAccessor() .getArrayItems(myDebugValue, key.first, key.second, Math.min(CHUNK_ROW_SIZE, getRowCount() - key.first), Math.min(CHUNK_COL_SIZE, getColumnCount() - key.second), myDataProvider.getFormat()); handleChunkAdded(key.first, key.second, chunk); return chunk; }); - - myExecutorService.execute(task); - - return task; } }); @@ -105,7 +104,13 @@ public class AsyncArrayTableModel extends AbstractTableModel { } } else { - chunk.addListener(() -> UIUtil.invokeLaterIfNeeded(() -> fireTableCellUpdated(row, col)), myExecutorService); + myQueue.queue(new Update("get chunk from debugger") { + @Override + public void run() { + chunk.addListener(() -> UIUtil.invokeLaterIfNeeded(() -> fireTableDataChanged()), myExecutorService); + myExecutorService.execute(((ListenableFutureTask)chunk)); + } + }); } return EMPTY_CELL_VALUE; }