@@ -21,6 +21,7 @@ const SMALL_HISTOGRAM_NUM_BINS = 80;
21
21
const LARGE_HISTOGRAM_NUM_BINS = 200 ;
22
22
const SMALL_FREQUENCY_TABLE_LIMIT = 8 ;
23
23
const LARGE_FREQUENCY_TABLE_LIMIT = 16 ;
24
+ const UPDATE_EVENT_DEBOUNCE_DELAY = 50 ;
24
25
25
26
/**
26
27
* UpdateDescriptor interface.
@@ -54,6 +55,11 @@ export class TableSummaryCache extends Disposable {
54
55
*/
55
56
private _trimCacheTimeout ?: Timeout ;
56
57
58
+ /**
59
+ * Gets or sets the debounced update event timeout.
60
+ */
61
+ private _debouncedUpdateTimeout ?: Timeout ;
62
+
57
63
/**
58
64
* The search text used to filter the dataset in the column schema
59
65
* and column profile caches. The last search text value is maintained
@@ -146,6 +152,9 @@ export class TableSummaryCache extends Disposable {
146
152
// Clear the trim cache timeout.
147
153
this . clearTrimCacheTimeout ( ) ;
148
154
155
+ // Clear the debounced update timeout.
156
+ this . clearDebouncedUpdateTimeout ( ) ;
157
+
149
158
// Call the base class's dispose method.
150
159
super . dispose ( ) ;
151
160
}
@@ -676,27 +685,36 @@ export class TableSummaryCache extends Disposable {
676
685
677
686
const tableState = await this . _dataExplorerClientInstance . getBackendState ( ) ;
678
687
679
- // For more than 10 million rows, we request profiles one by one rather than as a batch for
688
+ // For more than 1 million rows, we request profiles one by one rather than as a batch for
680
689
// better responsiveness
681
- const BATCHING_THRESHOLD = 5_000_000 ;
690
+ const BATCHING_THRESHOLD = 1_000_000 ;
682
691
if ( tableState . table_shape . num_rows > BATCHING_THRESHOLD ) {
683
- const BATCH_SIZE = 4 ;
684
- for ( let i = 0 ; i < columnIndices . length ; i += BATCH_SIZE ) {
685
- // Get the next batch of up to 4 requests
686
- const batchColumnRequests = columnRequests . slice ( i , i + BATCH_SIZE ) ;
687
- const batchColumnIndices = columnIndices . slice ( i , i + BATCH_SIZE ) ;
688
-
689
- // Send the batch of requests to getColumnProfiles
690
- const results = await this . _dataExplorerClientInstance . getColumnProfiles ( batchColumnRequests ) ;
691
-
692
- // Cache the returned column profiles for each index in the batch
693
- for ( let j = 0 ; j < results . length ; j ++ ) {
694
- this . _columnProfileCache . set ( batchColumnIndices [ j ] , results [ j ] ) ;
695
- }
692
+ // Start all requests and store promises
693
+ const profilePromises = columnRequests . map ( ( columnRequest , index ) => {
694
+ const columnIndex = columnIndices [ index ] ;
695
+
696
+ // Start the request and handle result immediately when it completes
697
+ const promise = this . _dataExplorerClientInstance . getColumnProfiles ( [ columnRequest ] )
698
+ . then ( results => {
699
+ // Cache the result as soon as it's available
700
+ if ( results . length > 0 ) {
701
+ this . _columnProfileCache . set ( columnIndex , results [ 0 ] ) ;
702
+ }
703
+ // Fire the onDidUpdate event with debouncing for smoother updates
704
+ this . fireOnDidUpdateDebounced ( ) ;
705
+ return results ;
706
+ } )
707
+ . catch ( error => {
708
+ // Handle errors gracefully
709
+ console . error ( `Failed to get column profile for index ${ columnIndex } :` , error ) ;
710
+ throw error ;
711
+ } ) ;
712
+
713
+ return promise ;
714
+ } ) ;
696
715
697
- // Fire the onDidUpdate event so things update as soon as they are returned
698
- this . _onDidUpdateEmitter . fire ( ) ;
699
- }
716
+ // Wait for all requests to complete
717
+ await Promise . allSettled ( profilePromises ) ;
700
718
} else {
701
719
// Load the column profiles as a batch
702
720
const columnProfileResults = await this . _dataExplorerClientInstance . getColumnProfiles (
@@ -764,6 +782,31 @@ export class TableSummaryCache extends Disposable {
764
782
}
765
783
}
766
784
785
+ /**
786
+ * Clears the debounced update timeout.
787
+ */
788
+ private clearDebouncedUpdateTimeout ( ) {
789
+ // If there is a debounced update timeout scheduled, clear it.
790
+ if ( this . _debouncedUpdateTimeout ) {
791
+ clearTimeout ( this . _debouncedUpdateTimeout ) ;
792
+ this . _debouncedUpdateTimeout = undefined ;
793
+ }
794
+ }
795
+
796
+ /**
797
+ * Fires the onDidUpdate event with debouncing to smooth incremental updates.
798
+ */
799
+ private fireOnDidUpdateDebounced ( ) {
800
+ // Clear any existing debounced update timeout.
801
+ this . clearDebouncedUpdateTimeout ( ) ;
802
+
803
+ // Set a new debounced update timeout.
804
+ this . _debouncedUpdateTimeout = setTimeout ( ( ) => {
805
+ this . _debouncedUpdateTimeout = undefined ;
806
+ this . _onDidUpdateEmitter . fire ( ) ;
807
+ } , UPDATE_EVENT_DEBOUNCE_DELAY ) ;
808
+ }
809
+
767
810
/**
768
811
* Trims the data in the cache if the key is not in the provided list.
769
812
* @param columnIndicesToKeep The array of column indices to keep in the cache.
0 commit comments