perf(core): offload LunarCache precomputing and batch calculation to Dispatchers.Default

This commit is contained in:
xfy 2026-07-24 13:34:02 +08:00
parent 1b2fcfe248
commit fc2f2065df
2 changed files with 7 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package plus.rua.project
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@ -81,7 +82,7 @@ class CalendarViewModel(
getMonthGridInfo(normalizedYear, normalizedMonth)
}
viewModelScope.launch {
viewModelScope.launch(Dispatchers.Default) {
monthsToPrecompute.forEach { info ->
val dates = (0 until info.totalDays).map { i ->
info.startDate.plus(DatePeriod(days = i))

View File

@ -33,6 +33,8 @@ import plus.rua.project.DayCellInfo
import plus.rua.project.LunarCache
import plus.rua.project.ShiftKind
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* 月度日历网格页面支持两阶段折叠动画
@ -80,7 +82,9 @@ fun CalendarMonthPage(
key1 = year,
key2 = month
) {
value = LunarCache.default.getOrComputeBatch(days.map { it.date })
value = withContext(Dispatchers.Default) {
LunarCache.default.getOrComputeBatch(days.map { it.date })
}
}
val holidayEdges = remember(lunarDataMap, year, month) {