Skip to content

Commit 268059d

Browse files
committed
Debounce rendering events and reduce concurrency in Python for 1-at-a-time requests
1 parent e58e87b commit 268059d

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

extensions/positron-python/python_files/posit/positron/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import functools
99
import inspect
1010
import logging
11+
import os
1112
import sys
1213
import threading
1314
import uuid
@@ -146,7 +147,9 @@ class BackgroundJobQueue:
146147

147148
def __init__(self, max_workers=None):
148149
# Initialize the ThreadPoolExecutor with the specified number
149-
# of workers
150+
# of workers. Default to the number of CPU cores for optimal performance.
151+
if max_workers is None:
152+
max_workers = os.cpu_count() or 4
150153
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
151154
self.pending_futures = set()
152155
self.lock = threading.Lock()

src/vs/workbench/services/positronDataExplorer/common/tableSummaryCache.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const SMALL_HISTOGRAM_NUM_BINS = 80;
2020
const LARGE_HISTOGRAM_NUM_BINS = 200;
2121
const SMALL_FREQUENCY_TABLE_LIMIT = 8;
2222
const LARGE_FREQUENCY_TABLE_LIMIT = 16;
23+
const UPDATE_EVENT_DEBOUNCE_DELAY = 50;
2324

2425
/**
2526
* UpdateDescriptor interface.
@@ -52,6 +53,11 @@ export class TableSummaryCache extends Disposable {
5253
*/
5354
private _trimCacheTimeout?: Timeout;
5455

56+
/**
57+
* Gets or sets the debounced update event timeout.
58+
*/
59+
private _debouncedUpdateTimeout?: Timeout;
60+
5561
/**
5662
* The search text used to filter the dataset in the column schema
5763
* and column profile caches. The last search text value is maintained
@@ -126,6 +132,9 @@ export class TableSummaryCache extends Disposable {
126132
// Clear the trim cache timeout.
127133
this.clearTrimCacheTimeout();
128134

135+
// Clear the debounced update timeout.
136+
this.clearDebouncedUpdateTimeout();
137+
129138
// Call the base class's dispose method.
130139
super.dispose();
131140
}
@@ -465,8 +474,8 @@ export class TableSummaryCache extends Disposable {
465474
if (results.length > 0) {
466475
this._columnProfileCache.set(columnIndex, results[0]);
467476
}
468-
// Fire the onDidUpdate event immediately
469-
this._onDidUpdateEmitter.fire();
477+
// Fire the onDidUpdate event with debouncing for smoother updates
478+
this.fireOnDidUpdateDebounced();
470479
return results;
471480
})
472481
.catch(error => {
@@ -547,6 +556,31 @@ export class TableSummaryCache extends Disposable {
547556
}
548557
}
549558

559+
/**
560+
* Clears the debounced update timeout.
561+
*/
562+
private clearDebouncedUpdateTimeout() {
563+
// If there is a debounced update timeout scheduled, clear it.
564+
if (this._debouncedUpdateTimeout) {
565+
clearTimeout(this._debouncedUpdateTimeout);
566+
this._debouncedUpdateTimeout = undefined;
567+
}
568+
}
569+
570+
/**
571+
* Fires the onDidUpdate event with debouncing to smooth incremental updates.
572+
*/
573+
private fireOnDidUpdateDebounced() {
574+
// Clear any existing debounced update timeout.
575+
this.clearDebouncedUpdateTimeout();
576+
577+
// Set a new debounced update timeout.
578+
this._debouncedUpdateTimeout = setTimeout(() => {
579+
this._debouncedUpdateTimeout = undefined;
580+
this._onDidUpdateEmitter.fire();
581+
}, UPDATE_EVENT_DEBOUNCE_DELAY);
582+
}
583+
550584
/**
551585
* Trims the data in the cache that is not contained between start and end column index.
552586
* @param startColumnIndex The start column index.

0 commit comments

Comments
 (0)