feat: Add IrisGridCacheUtils for memoizing iris grid state#2416
feat: Add IrisGridCacheUtils for memoizing iris grid state#2416mattrunyon merged 5 commits intodeephaven:mainfrom
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2416 +/- ##
==========================================
+ Coverage 46.84% 46.92% +0.08%
==========================================
Files 711 712 +1
Lines 39319 39340 +21
Branches 9826 10024 +198
==========================================
+ Hits 18418 18462 +44
+ Misses 20890 20824 -66
- Partials 11 54 +43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the dehydration logic in IrisGridUtils by memoizing both grid state and Iris grid state conversion methods to improve performance and consistency. Key changes include updating type definitions and functions in IrisGridUtils.ts, revising corresponding tests in IrisGridUtils.test.ts, and simplifying state retrieval in IrisGridPanel.tsx.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/iris-grid/src/IrisGridUtils.ts | Added memoization for dehydrateGridState and dehydrateIrisGridState with updated type definitions and equality checks. |
| packages/iris-grid/src/IrisGridUtils.test.ts | Updated and added tests to verify serialization and memoization behavior. |
| packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx | Removed redundant memoization wrappers in favor of direct dehydration function calls. |
Comments suppressed due to low confidence (2)
packages/iris-grid/src/IrisGridUtils.ts:1298
- Ensure that the 'metrics' property is always defined in 'irisGridState' to avoid unintended cache invalidation within the equality function. If 'metrics' could be undefined, adjust the equality check or enforce its presence.
return (a[0] === b[0] && a[1].metrics != null && b[1].metrics != null && a[1].metrics.userColumnWidths === b[1].metrics.userColumnWidths && a[1].metrics.userRowHeights === b[1].metrics.userRowHeights && compareStateKeys.every(key => a[1][key] === b[1][key]));
packages/iris-grid/src/IrisGridUtils.test.ts:705
- [nitpick] Consider adding tests that vary individual properties within 'irisGridState' to ensure the custom equality function in memoizeOne accurately detects changes. This will improve confidence in the memoization logic under edge cases.
test('dehydrateIrisGridState should be serializable and memoized', () => {
There was a problem hiding this comment.
Pull Request Overview
This PR refactors iris grid state dehydration by introducing memoization to improve performance and streamline state comparison in both grid and IrisGrid utilities. Key changes include:
- Refactoring dehydrate/hydrate functions in IrisGridUtils with updated types and default fallback values.
- Introducing new memoized cache utilities in IrisGridCacheUtils with corresponding tests.
- Updating IrisGridPanel to leverage the new memoization functions for state dehydration.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/iris-grid/src/index.ts | Export added for IrisGridCacheUtils. |
| packages/iris-grid/src/IrisGridUtils.ts | Updated types and refactored dehydration/hydration functions with improved defaults. |
| packages/iris-grid/src/IrisGridUtils.test.ts | Updated tests to reflect new function signatures and naming. |
| packages/iris-grid/src/IrisGridCacheUtils.ts | New cache utilities using memoization are provided. |
| packages/iris-grid/src/IrisGridCacheUtils.test.ts | Tests for the memoization logic have been added/updated. |
| packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx | Removed inline memoization in favor of the new cache utilities and updated state dehydration usage. |
Comments suppressed due to low confidence (2)
packages/iris-grid/src/IrisGridUtils.test.ts:666
- The test label 'dehydrateIrisGridState' does not match the function being invoked ('dehydrateGridState'); consider updating the label for consistency and clarity.
'dehydrateIrisGridState',
packages/iris-grid/src/IrisGridUtils.ts:1169
- Confirm that the default fallback for metrics is intentional; using fallback values could mask cases where metrics are unexpectedly undefined.
metrics: { userColumnWidths, userRowHeights } = { userColumnWidths: EMPTY_MAP, userRowHeights: EMPTY_MAP },
| isStuckToBottom: boolean; | ||
| isStuckToRight: boolean; | ||
| movedColumns: { | ||
| movedColumns: readonly { |
Adds
IrisGridCacheUtilswhich provides 3 methods to create memoized dehydrators:makeMemoizedGridStateDehydrator,makeMemoizedIrisGridStateDehydrator, andmakeMemoizedCombinedGridStateDehydrator. The first 2 are used forIrisGridPanelwhich saves the state under separate keys forgridStateandirisGridState. The 3rd is for newer uses likeUITablewhich can just save the combined state and spread it toIrisGridsinceIrisGridaccepts bothGridStateandIrisGridStateprops.Added tests for
dehydrateIrisGridState.Improved the
memoize-onetype override to infer the types of the equality function based on the actual function args.