Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions TablePro/Models/Query/RowProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ final class InMemoryRowProvider: RowProvider {

/// Lazy per-cell cache for formatted display values.
/// Keyed by source row index (buffer index or offset appended index).
/// Evicted when exceeding maxDisplayCacheSize to bound memory.
private var displayCache: [Int: [String?]] = [:]
private static let maxDisplayCacheSize = 20_000
private(set) var columnDefaults: [String: String?]
private(set) var columnTypes: [ColumnType]
private(set) var columnForeignKeys: [String: ForeignKeyInfo]
Expand Down Expand Up @@ -214,9 +216,16 @@ final class InMemoryRowProvider: RowProvider {
rowCache[col] = CellDisplayFormatter.format(src[col], columnType: ct)
}
displayCache[cacheKey] = rowCache
evictDisplayCacheIfNeeded(nearKey: cacheKey)
return columnIndex < rowCache.count ? rowCache[columnIndex] : nil
}

private func evictDisplayCacheIfNeeded(nearKey: Int) {
guard displayCache.count > Self.maxDisplayCacheSize else { return }
let halfSize = Self.maxDisplayCacheSize / 2
displayCache = displayCache.filter { abs($0.key - nearKey) <= halfSize }
}

@MainActor
func preWarmDisplayCache(upTo rowCount: Int) {
let count = min(rowCount, totalRowCount)
Expand Down
4 changes: 2 additions & 2 deletions TablePro/Views/Main/Child/MainEditorContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ struct MainEditorContentView: View {
return cached.sortedIndices
}

// For large datasets sorted async, return nil (unsorted) until cache is ready
if rows.count > 10_000 {
// For datasets sorted async, return nil (unsorted) until cache is ready
if rows.count > 1_000 {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions TablePro/Views/Main/MainContentCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,8 @@ final class MainContentCoordinator {
let sortColumns = currentSort.columns
let colTypes = tab.columnTypes

if rows.count > 10_000 {
// Large dataset: sort on background thread to avoid UI freeze
if rows.count > 1_000 {
// Sort on background thread to avoid UI freeze
activeSortTasks[tabId]?.cancel()
activeSortTasks.removeValue(forKey: tabId)
tabManager.tabs[tabIndex].isExecuting = true
Expand Down
Loading