@@ -262,7 +262,7 @@ export class GridMetricCalculator {
262262 const treePaddingY = 0 ; // We don't support trees on columns (at least not yet)
263263
264264 const visibleRowHeights = this . getVisibleRowHeights ( state ) ;
265- const visibleColumnWidths = this . getVisibleColumnWidths (
265+ const [ visibleColumnWidths , columnsForRender ] = this . getVisibleColumnWidths (
266266 state ,
267267 firstColumn ,
268268 treePaddingX
@@ -612,10 +612,13 @@ export class GridMetricCalculator {
612612 scrollableViewportWidth,
613613 scrollableViewportHeight,
614614
615- // Array of visible rows/columns, by grid index
615+ // Array of visible (i.e., in the viewport) rows/columns, by VisibleIndex
616616 visibleRows,
617617 visibleColumns,
618618
619+ // Array of visible, non-hidden columns, by VisibleIndex
620+ columnsForRender,
621+
619622 // Map of the height/width of columns in the viewport (excluding floating columns)
620623 visibleRowHeights,
621624 visibleColumnWidths,
@@ -1060,18 +1063,19 @@ export class GridMetricCalculator {
10601063 /**
10611064 * Retrieve a map of the width of all the visible columns (non-floating)
10621065 * @param state The grid metric state
1063- * @returns The widths of all the visible columns
1066+ * @returns The widths of all the visible columns and an array of visible, non-hidden columns
10641067 */
10651068 getVisibleColumnWidths (
10661069 state : GridMetricState ,
10671070 firstColumn : VisibleIndex = this . getFirstColumn ( state ) ,
10681071 treePaddingX : number = this . calculateTreePaddingX ( state )
1069- ) : SizeMap {
1072+ ) : [ SizeMap , VisibleIndex [ ] ] {
10701073 const { left, leftOffset, width, model } = state ;
10711074
10721075 let x = 0 ;
10731076 let column = left ;
10741077 const columnWidths = new Map ( ) ;
1078+ const columnsForRender : VisibleIndex [ ] = [ ] ;
10751079 const { columnCount, floatingRightColumnCount } = model ;
10761080 while (
10771081 x < width + leftOffset &&
@@ -1084,11 +1088,14 @@ export class GridMetricCalculator {
10841088 treePaddingX
10851089 ) ;
10861090 columnWidths . set ( column , columnWidth ) ;
1091+ if ( columnWidth > 0 ) {
1092+ columnsForRender . push ( column ) ;
1093+ }
10871094 x += columnWidth ;
10881095 column += 1 ;
10891096 }
10901097
1091- return columnWidths ;
1098+ return [ columnWidths , columnsForRender ] ;
10921099 }
10931100
10941101 /**
@@ -1706,6 +1713,13 @@ export class GridMetricCalculator {
17061713 return columnWidth ;
17071714 }
17081715
1716+ const cachedValue = this . calculatedColumnWidths . get ( modelColumn ) ;
1717+
1718+ // Performance optimization: if the column is hidden and has a cached value, avoid recalculating until the column is shown again
1719+ if ( cachedValue != null && this . isColumnHidden ( modelColumn ) ) {
1720+ return cachedValue ;
1721+ }
1722+
17091723 const headerWidth = this . calculateColumnHeaderWidth (
17101724 modelColumn ,
17111725 state ,
@@ -1716,7 +1730,6 @@ export class GridMetricCalculator {
17161730 state ,
17171731 maxColumnWidth
17181732 ) ;
1719- const cachedValue = this . calculatedColumnWidths . get ( modelColumn ) ;
17201733 let columnWidth = Math . ceil ( Math . max ( headerWidth , dataWidth ) ) ;
17211734 columnWidth = Math . max ( minColumnWidth , columnWidth ) ;
17221735 columnWidth = Math . min ( maxColumnWidth , columnWidth ) ;
@@ -1737,6 +1750,21 @@ export class GridMetricCalculator {
17371750 return columnWidth ;
17381751 }
17391752
1753+ /**
1754+ * Checks if a column is hidden either by a user setting the width to 0 or by initial width being 0
1755+ * @param modelIndex the model index of the column to check
1756+ * @returns true if the column is hidden, false otherwise
1757+ */
1758+ isColumnHidden ( modelIndex : ModelIndex ) : boolean {
1759+ const userSetWidth = this . userColumnWidths . get ( modelIndex ) ;
1760+ // The column is hidden if the user set the width to 0 or if the initial width is 0 and the user hasn't set a width
1761+ return (
1762+ userSetWidth === 0 ||
1763+ ( userSetWidth === undefined &&
1764+ this . initialColumnWidths . get ( modelIndex ) === 0 )
1765+ ) ;
1766+ }
1767+
17401768 /**
17411769 * Calculate the width of the specified column's header
17421770 * @param modelColumn ModelIndex of the column to get the header width for
0 commit comments