table
table copied to clipboard
Performance of calculateCellHeights
π 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.