@@ -1710,6 +1710,13 @@ export class GridMetricCalculator {
17101710 return columnWidth ;
17111711 }
17121712
1713+ const cachedValue = this . calculatedColumnWidths . get ( modelColumn ) ;
1714+
1715+ // Performance optimization: if the column is hidden and has a cached value, avoid recalculating until the column is shown again
1716+ if ( cachedValue != null && this . isColumnHidden ( modelColumn ) ) {
1717+ return cachedValue ;
1718+ }
1719+
17131720 const headerWidth = this . calculateColumnHeaderWidth (
17141721 modelColumn ,
17151722 state ,
@@ -1720,7 +1727,6 @@ export class GridMetricCalculator {
17201727 state ,
17211728 maxColumnWidth
17221729 ) ;
1723- const cachedValue = this . calculatedColumnWidths . get ( modelColumn ) ;
17241730 let columnWidth = Math . ceil ( Math . max ( headerWidth , dataWidth ) ) ;
17251731 columnWidth = Math . max ( minColumnWidth , columnWidth ) ;
17261732 columnWidth = Math . min ( maxColumnWidth , columnWidth ) ;
@@ -1741,6 +1747,21 @@ export class GridMetricCalculator {
17411747 return columnWidth ;
17421748 }
17431749
1750+ /**
1751+ * Checks if a column is hidden either by a user setting the width to 0 or by initial width being 0
1752+ * @param modelIndex the model index of the column to check
1753+ * @returns true if the column is hidden, false otherwise
1754+ */
1755+ isColumnHidden ( modelIndex : ModelIndex ) : boolean {
1756+ const userSetWidth = this . userColumnWidths . get ( modelIndex ) ;
1757+ // 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
1758+ return (
1759+ userSetWidth === 0 ||
1760+ ( userSetWidth === undefined &&
1761+ this . initialColumnWidths . get ( modelIndex ) === 0 )
1762+ ) ;
1763+ }
1764+
17441765 /**
17451766 * Calculate the width of the specified column's header
17461767 * @param modelColumn ModelIndex of the column to get the header width for
0 commit comments