-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Open
Labels
area: cdk/scrollingfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesgemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by geminineeds triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team
Description
Feature Description
Description:
Problem Statement
The current AutoSizeVirtualScrollStrategy implementation relies on ItemSizeAverager to estimate the size of unseen items based on historical measurements. While this approach works for many scenarios, it has several limitations:
- Reflow overhead: Must render elements first before measuring, triggering expensive layout reflows
- Inaccurate predictions: Averaging-based estimation can be imprecise for heterogeneous content, especially variable-height text items
- Performance bottlenecks: Frequent DOM measurements during scrolling impact performance
- Layout shifts: Predictive scrolling may cause visual jumps when estimated sizes differ significantly from actual sizes
Proposed Solution
I'd like to propose integrating the Pretext library (https://github.com/chenglou/pretext) into the auto-size virtual scroll strategy. Pretext is a pure JavaScript/TypeScript library that provides:
- Accurate text measurement without DOM: Calculates text dimensions using pure arithmetic, avoiding
getBoundingClientRectandoffsetHeight - Excellent performance: Benchmarks show
layout()operations at ~0.09ms for 500 texts (hot path) - Comprehensive language support: Handles all languages, emojis, and mixed-bidi text correctly
- Predictive sizing: Enables pre-rendering size calculations for virtual lists
Implementation Ideas
The integration could work as follows:
-
For text-heavy virtual lists:
- When items contain primarily text content with known font/line-height configurations
- Use Pretext's
prepare()+layout()API to calculate heights before rendering - This allows the scroll strategy to know exact item sizes upfront
-
Hybrid approach:
- Use Pretext for text content measurement
- Fall back to current DOM measurement for non-text or complex layouts
- Combine both for maximum accuracy
-
Performance optimization:
- Cache
PreparedTextobjects for reuse during resize events - Only re-run
layout()(the cheap 0.09ms operation) when container width changes
- Cache
Benefits
- Eliminates layout reflow for text measurement in virtual lists
- More accurate scrolling behavior with predictable item sizes
- Better performance especially for long lists with variable-height text items
- Reduced visual jumps during scrolling since sizes are pre-calculated
- Support for all languages and scripts including complex layouts
Example Use Case
- Chat applications with varying message lengths.
- Feeds/Dashboards with dynamic text content.
Use Case
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: cdk/scrollingfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesgemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by geminineeds triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team