Large Datasets
Handle 100,000+ rows with smooth 60fps scrolling using lazy measurement.
The Challenge
Large datasets present two problems:
- Memory - Loading all row heights upfront consumes memory
- Startup time - Measuring all rows delays initial display
SwiftDataTables solves both with lazy measurement.
Enabling Large-Scale Mode
var config = DataTableConfiguration()
config.rowHeightMode = .automatic(estimated: 44, prefetchWindow: 10)
let dataTable = SwiftDataTable(
data: massiveDataset, // 100,000+ items
columns: columns,
options: config
)How Lazy Measurement Works
- Estimated Heights - Initially, all rows use the estimated height. This enables instant startup.
- On-Demand Measurement - As rows scroll into view, they're measured.
- Prefetch Window - Rows within the prefetch window are measured ahead of time.
- Automatic Anchoring - When heights change, scroll position is preserved.
Best Practices
1. Choose a Good Estimate
// Measure a few sample rows to find the average
let sampleHeights = [52, 48, 44, 56, 48]
let average = sampleHeights.reduce(0, +) / sampleHeights.count // 50
config.rowHeightMode = .automatic(estimated: CGFloat(average), prefetchWindow: 10)2. Use Fixed Heights When Possible
// Fastest option for uniform content
config.rowHeightMode = .fixed(44)3. Tune the Prefetch Window
| Scroll Speed | Recommended Window |
|---|---|
| Slow/normal | 5-10 |
| Fast/flicking | 15-20 |
| Programmatic jumps | 20+ |
Column Width Optimization
// Fast: estimate from character count
config.columnWidthMode = .fitContentText(strategy: .estimatedAverage(averageCharWidth: 8))
// Or: sample-based (still fast)
config.columnWidthMode = .fitContentText(strategy: .hybrid(sampleSize: 100, averageCharWidth: 7))
// Avoid for large datasets: measure every row
// config.columnWidthMode = .fitContentText(strategy: .maxMeasured) // Slow!Avoid .maxMeasured for large datasets as it measures every row upfront.