table icon indicating copy to clipboard operation
table copied to clipboard

Performance of calculateCellHeights

Open alexgavrushenko opened this issue 5 months ago β€’ 0 comments

πŸ› Issue

When rendering large datasets that contain newline characters, there is significant performance degradation.
This is caused by excessive GC pressure due to unnecessary .split() and .splice() operations during wrapping and height calculations.


πŸ§ͺ Current Workaround

To mitigate the issue in production use, I implemented a lazy-loading approach for rendering tables (e.g., recent traceback list), loading content in parts and merging the final table at runtime.


βœ… Proposed Solution

Optimize the height calculation logic by using a regex .exec() in a loop instead of .split() and .wrap() to count line breaks.
This avoids allocating large arrays and reduces GC overhead during render-heavy scenarios.


πŸ” What Could Be Improved

  • Regex optimizations: Current regex expressions in wrap* functions could be reviewed and optimized for better performance.
  • Memoization opportunities:
    • Splitting and wrapping operations could potentially be memoized.
    • Alternatively, these computations might be moved outside of the render cycle if inputs don’t change.
    • Needs further investigation.
  • Potential side effects:
    • The solution introduces a looser coupling with the wrapping algorithm, which may lead to unexpected rendering behavior in some edge cases.
    • Consider making this height calculation strategy configurable, so it can be enabled explicitly when needed.

alexgavrushenko avatar Jul 14 '25 18:07 alexgavrushenko