perf: 移除临时性能监控日志,保留 Perfetto trace 标记

清理 ViewModel 和各 UI 组件中用于调试的 println 性能日志、
重组计数器和 System.nanoTime() 计时代码。正式的
composeTraceBeginSection/EndSection Perfetto/Systrace 标记继续保留,
用于生产环境性能分析。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-21 11:46:12 +08:00
parent 98f3b71c4f
commit 2bd7d5ee19
6 changed files with 3 additions and 152 deletions

View File

@ -25,28 +25,6 @@ import plus.rua.project.ui.COLLAPSE_THRESHOLD
import plus.rua.project.ui.FLING_VELOCITY_THRESHOLD_DP import plus.rua.project.ui.FLING_VELOCITY_THRESHOLD_DP
import kotlin.time.Clock import kotlin.time.Clock
// region 性能监控工具
private fun perfLog(tag: String, msg: String) {
println("[PERF:${Thread.currentThread().name}] $tag | $msg")
}
private inline fun <T> perfMeasure(tag: String, block: () -> T): T {
val start = System.nanoTime()
val result = block()
val elapsedMs = (System.nanoTime() - start) / 1_000_000.0
perfLog(tag, "elapsed=${"%.3f".format(elapsedMs)}ms")
return result
}
private inline fun <T> perfMeasureResult(tag: String, block: () -> T): T {
val start = System.nanoTime()
val result = block()
val elapsedMs = (System.nanoTime() - start) / 1_000_000.0
perfLog(tag, "result=$result elapsed=${"%.3f".format(elapsedMs)}ms")
return result
}
// endregion
/** /**
* 日历日期数据用于网格单元格渲染 * 日历日期数据用于网格单元格渲染
* *
@ -173,53 +151,32 @@ class CalendarViewModel(
* 当前视图被直接移除动画只作用在目标视图的 scale/alpha * 当前视图被直接移除动画只作用在目标视图的 scale/alpha
*/ */
fun toggleYearView() { fun toggleYearView() {
val direction = if (isYearView) "Year→Month" else "Month→Year"
perfLog("VM.toggleYearView", "START direction=$direction isCollapsed=$isCollapsed yearViewYear=$yearViewYear selectedDate=$selectedDate")
val toggleStart = System.nanoTime()
yearViewJob?.cancel() yearViewJob?.cancel()
yearViewJob = coroutineScope.launch { yearViewJob = coroutineScope.launch {
if (isYearView) { if (isYearView) {
composeTraceBeginSection("YearView→MonthView") composeTraceBeginSection("YearView→MonthView")
val snapStart = System.nanoTime()
_yearViewAnimatable.snapTo(1f) _yearViewAnimatable.snapTo(1f)
perfLog("VM.toggleYearView", "snapTo(1f) elapsed=${(System.nanoTime() - snapStart) / 1_000_000.0}ms") launch {
val animJob = launch {
val animStart = System.nanoTime()
_yearViewAnimatable.animateTo( _yearViewAnimatable.animateTo(
0f, tween(400, easing = FastOutSlowInEasing) 0f, tween(400, easing = FastOutSlowInEasing)
) )
perfLog("VM.toggleYearView", "animateTo(0f) elapsed=${(System.nanoTime() - animStart) / 1_000_000.0}ms")
} }
val frameStart = System.nanoTime()
withFrameNanos { } withFrameNanos { }
perfLog("VM.toggleYearView", "withFrameNanos elapsed=${(System.nanoTime() - frameStart) / 1_000_000.0}ms")
val flipStart = System.nanoTime()
isYearView = false isYearView = false
perfLog("VM.toggleYearView", "isYearView=false flip elapsed=${(System.nanoTime() - flipStart) / 1_000_000.0}ms")
composeTraceEndSection() composeTraceEndSection()
} else { } else {
composeTraceBeginSection("MonthView→YearView") composeTraceBeginSection("MonthView→YearView")
val snapStart = System.nanoTime()
yearViewYear = selectedDate.year yearViewYear = selectedDate.year
_yearViewAnimatable.snapTo(0f) _yearViewAnimatable.snapTo(0f)
perfLog("VM.toggleYearView", "snapTo(0f) + set yearViewYear=$yearViewYear elapsed=${(System.nanoTime() - snapStart) / 1_000_000.0}ms") launch {
val animJob = launch {
val animStart = System.nanoTime()
_yearViewAnimatable.animateTo( _yearViewAnimatable.animateTo(
1f, tween(400, easing = FastOutSlowInEasing) 1f, tween(400, easing = FastOutSlowInEasing)
) )
perfLog("VM.toggleYearView", "animateTo(1f) elapsed=${(System.nanoTime() - animStart) / 1_000_000.0}ms")
} }
val frameStart = System.nanoTime()
withFrameNanos { } withFrameNanos { }
perfLog("VM.toggleYearView", "withFrameNanos elapsed=${(System.nanoTime() - frameStart) / 1_000_000.0}ms")
val flipStart = System.nanoTime()
isYearView = true isYearView = true
perfLog("VM.toggleYearView", "isYearView=true flip elapsed=${(System.nanoTime() - flipStart) / 1_000_000.0}ms")
composeTraceEndSection() composeTraceEndSection()
} }
val totalMs = (System.nanoTime() - toggleStart) / 1_000_000.0
perfLog("VM.toggleYearView", "END direction=$direction total=${"%.3f".format(totalMs)}ms")
} }
} }
@ -228,27 +185,17 @@ class CalendarViewModel(
*/ */
@Suppress("DEPRECATION") // monthNumber 无替代 API @Suppress("DEPRECATION") // monthNumber 无替代 API
fun selectMonthFromYearView(month: Int) { fun selectMonthFromYearView(month: Int) {
val totalStart = System.nanoTime()
perfLog("VM.selectMonthFromYearView", "START month=$month yearViewYear=$yearViewYear")
composeTraceBeginSection("YearView:SelectMonth") composeTraceBeginSection("YearView:SelectMonth")
val date = if (yearViewYear == today.year && today.month.number == month) today val date = if (yearViewYear == today.year && today.month.number == month) today
else LocalDate(yearViewYear, month, 1) else LocalDate(yearViewYear, month, 1)
val dateSetStart = System.nanoTime()
selectedDate = date selectedDate = date
perfLog("VM.selectMonthFromYearView", "selectedDate=$selectedDate elapsed=${(System.nanoTime() - dateSetStart) / 1_000_000.0}ms")
val flipStart = System.nanoTime()
isYearView = false isYearView = false
perfLog("VM.selectMonthFromYearView", "isYearView=false elapsed=${(System.nanoTime() - flipStart) / 1_000_000.0}ms")
yearViewJob?.cancel() yearViewJob?.cancel()
yearViewJob = coroutineScope.launch { yearViewJob = coroutineScope.launch {
val animStart = System.nanoTime()
_yearViewAnimatable.animateTo( _yearViewAnimatable.animateTo(
0f, tween(400, easing = FastOutSlowInEasing) 0f, tween(400, easing = FastOutSlowInEasing)
) )
perfLog("VM.selectMonthFromYearView", "animateTo(0f) elapsed=${(System.nanoTime() - animStart) / 1_000_000.0}ms")
composeTraceEndSection() composeTraceEndSection()
val totalMs = (System.nanoTime() - totalStart) / 1_000_000.0
perfLog("VM.selectMonthFromYearView", "END total=${"%.3f".format(totalMs)}ms")
} }
} }
@ -379,7 +326,6 @@ class CalendarViewModel(
*/ */
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
fun getMonthDays(year: Int, month: Int): List<CalendarDay> { fun getMonthDays(year: Int, month: Int): List<CalendarDay> {
val start = System.nanoTime()
composeTraceBeginSection("getMonthDays:$year-$month") composeTraceBeginSection("getMonthDays:$year-$month")
val firstOfMonth = LocalDate(year, month, 1) val firstOfMonth = LocalDate(year, month, 1)
val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal
@ -400,8 +346,6 @@ class CalendarViewModel(
) )
} }
composeTraceEndSection() composeTraceEndSection()
val elapsedMs = (System.nanoTime() - start) / 1_000_000.0
perfLog("VM.getMonthDays", "$year-$month rows=$rows totalDays=$totalDays elapsed=${"%.3f".format(elapsedMs)}ms")
return result return result
} }
} }

View File

@ -8,10 +8,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.graphicsLayer
@ -26,11 +23,6 @@ import kotlinx.datetime.number
import kotlinx.datetime.plus import kotlinx.datetime.plus
import plus.rua.project.ShiftKind import plus.rua.project.ShiftKind
// region 性能监控工具
private fun monthPagePerfLog(tag: String, msg: String) {
println("[MONTH-PAGE-PERF:${Thread.currentThread().name}] $tag | $msg")
}
// endregion
/** /**
* 月度日历网格页面支持两阶段折叠动画 * 月度日历网格页面支持两阶段折叠动画
@ -66,15 +58,8 @@ fun CalendarMonthPage(
onRowHeightMeasured: ((Int) -> Unit)? = null, onRowHeightMeasured: ((Int) -> Unit)? = null,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
val pageStart = System.nanoTime()
var recomposeCount by remember { mutableIntStateOf(0) }
recomposeCount++
val days = remember(year, month) { val days = remember(year, month) {
val genStart = System.nanoTime() generateMonthDays(year, month)
val result = generateMonthDays(year, month)
val genMs = (System.nanoTime() - genStart) / 1_000_000.0
monthPagePerfLog("CalendarMonthPage", "generateMonthDays year=$year month=$month elapsed=${"%.3f".format(genMs)}ms")
result
} }
val density = LocalDensity.current val density = LocalDensity.current
@ -82,8 +67,6 @@ fun CalendarMonthPage(
val anchorIndex = remember(weeks, selectedDate) { val anchorIndex = remember(weeks, selectedDate) {
weeks.indexOfFirst { week -> week.any { it.date == selectedDate } } weeks.indexOfFirst { week -> week.any { it.date == selectedDate } }
} }
val weekCount = weeks.size
monthPagePerfLog("CalendarMonthPage", "composition #$recomposeCount year=$year month=$month weeks=$weekCount collapseProgress=$collapseProgress anchorRow=$anchorIndex")
val hasAnchor = anchorIndex >= 0 val hasAnchor = anchorIndex >= 0
val h = rowHeightPx.toFloat() val h = rowHeightPx.toFloat()
@ -182,8 +165,6 @@ fun CalendarMonthPage(
} }
} }
} }
val totalMs = (System.nanoTime() - pageStart) / 1_000_000.0
monthPagePerfLog("CalendarMonthPage", "END year=$year month=$month elapsed=${"%.3f".format(totalMs)}ms")
} }
private data class DayData( private data class DayData(

View File

@ -77,12 +77,6 @@ import plus.rua.project.composeTraceEndSection
import kotlin.math.abs import kotlin.math.abs
import kotlin.time.Clock import kotlin.time.Clock
// region 性能监控工具
private fun uiPerfLog(tag: String, msg: String) {
println("[UI-PERF:${Thread.currentThread().name}] $tag | $msg")
}
// endregion
/** /**
* 日历主界面包含月/周视图切换折叠动画和年视图共享元素转场 * 日历主界面包含月/周视图切换折叠动画和年视图共享元素转场
* *
@ -114,10 +108,6 @@ fun CalendarMonthView(
isMenuExpanded = false isMenuExpanded = false
} }
// 重组计数器
var recomposeCount by remember { mutableIntStateOf(0) }
recomposeCount++
val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE }) val pagerState = rememberPagerState(initialPage = START_PAGE, pageCount = { Int.MAX_VALUE })
// 年视图分页器 // 年视图分页器
@ -158,7 +148,6 @@ fun CalendarMonthView(
} }
} }
uiPerfLog("CalendarMonthView", "composition #$recomposeCount isYearView=${viewModel.isYearView}")
Box( Box(
modifier = modifier modifier = modifier
.fillMaxSize() .fillMaxSize()
@ -174,7 +163,6 @@ fun CalendarMonthView(
targetState = viewModel.isYearView, targetState = viewModel.isYearView,
label = "month_year_transition", label = "month_year_transition",
transitionSpec = { transitionSpec = {
uiPerfLog("CalendarMonthView", "AnimatedContent transitionSpec target=$targetState initial=$initialState")
val enter = fadeIn(tween(300, easing = FastOutSlowInEasing)) + val enter = fadeIn(tween(300, easing = FastOutSlowInEasing)) +
slideInVertically(tween(300, easing = FastOutSlowInEasing)) { it / 6 } slideInVertically(tween(300, easing = FastOutSlowInEasing)) { it / 6 }
val exit = fadeOut(tween(200, easing = FastOutSlowInEasing)) + val exit = fadeOut(tween(200, easing = FastOutSlowInEasing)) +
@ -183,8 +171,6 @@ fun CalendarMonthView(
}, },
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) { isYearView -> ) { isYearView ->
val contentStart = System.nanoTime()
uiPerfLog("CalendarMonthView", "AnimatedContent content lambda START isYearView=$isYearView")
if (!isYearView) { if (!isYearView) {
composeTraceBeginSection("MonthView:Compose") composeTraceBeginSection("MonthView:Compose")
val layoutReady = rowHeightPx > 0 val layoutReady = rowHeightPx > 0
@ -242,13 +228,9 @@ fun CalendarMonthView(
) )
} }
} }
val monthViewMs = (System.nanoTime() - contentStart) / 1_000_000.0
uiPerfLog("CalendarMonthView", "MonthView content lambda END elapsed=${"%.3f".format(monthViewMs)}ms")
composeTraceEndSection() composeTraceEndSection()
} else { } else {
composeTraceBeginSection("YearView:Compose") composeTraceBeginSection("YearView:Compose")
val yearViewStart = System.nanoTime()
uiPerfLog("CalendarMonthView", "YearView:Compose START")
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -273,7 +255,6 @@ fun CalendarMonthView(
.fillMaxWidth() .fillMaxWidth()
.weight(1f) .weight(1f)
) { page -> ) { page ->
val pageStart = System.nanoTime()
val pageOffset = abs(yearPagerState.currentPageOffsetFraction) val pageOffset = abs(yearPagerState.currentPageOffsetFraction)
val isCurrentPage = page == yearPagerState.currentPage val isCurrentPage = page == yearPagerState.currentPage
val crossFadeAlpha = if (isCurrentPage) { val crossFadeAlpha = if (isCurrentPage) {
@ -282,7 +263,6 @@ fun CalendarMonthView(
pageOffset pageOffset
} }
val pageYear = viewModel.selectedDate.year + (page - START_PAGE) val pageYear = viewModel.selectedDate.year + (page - START_PAGE)
uiPerfLog("CalendarMonthView", "YearPager page=$page pageYear=$pageYear crossFadeAlpha=${"%.2f".format(crossFadeAlpha)} isCurrentPage=$isCurrentPage offset=${"%.3f".format(pageOffset)}")
YearGridView( YearGridView(
year = pageYear, year = pageYear,
selectedMonth = if (pageYear == currentYear) currentMonth else 0, selectedMonth = if (pageYear == currentYear) currentMonth else 0,
@ -304,12 +284,8 @@ fun CalendarMonthView(
) )
} }
} }
val yearViewMs = (System.nanoTime() - yearViewStart) / 1_000_000.0
uiPerfLog("CalendarMonthView", "YearView:Compose END elapsed=${"%.3f".format(yearViewMs)}ms")
composeTraceEndSection() composeTraceEndSection()
} }
val contentTotalMs = (System.nanoTime() - contentStart) / 1_000_000.0
uiPerfLog("CalendarMonthView", "AnimatedContent content lambda END total=${"%.3f".format(contentTotalMs)}ms")
} }
} }
@ -428,10 +404,6 @@ private fun CalendarPagerArea(
pagerState: PagerState, pagerState: PagerState,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
val areaStart = System.nanoTime()
var areaRecomposeCount by remember { mutableIntStateOf(0) }
areaRecomposeCount++
uiPerfLog("CalendarPagerArea", "composition #$areaRecomposeCount collapseProgress=${viewModel.collapseProgress} page=${pagerState.currentPage} rowHeightPx=$rowHeightPx")
val density = LocalDensity.current val density = LocalDensity.current
val collapseProgress = viewModel.collapseProgress val collapseProgress = viewModel.collapseProgress
@ -526,8 +498,6 @@ private fun CalendarPagerArea(
modifier = pagerModifier modifier = pagerModifier
) )
} }
val areaTotalMs = (System.nanoTime() - areaStart) / 1_000_000.0
uiPerfLog("CalendarPagerArea", "END elapsed=${"%.3f".format(areaTotalMs)}ms")
} }
@Composable @Composable

View File

@ -5,11 +5,8 @@ import androidx.compose.foundation.pager.PagerDefaults
import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.PagerState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
@ -20,11 +17,6 @@ import kotlinx.datetime.number
import plus.rua.project.ShiftKind import plus.rua.project.ShiftKind
import kotlin.math.abs import kotlin.math.abs
// region 性能监控工具
private fun pagerPerfLog(tag: String, msg: String) {
println("[PAGER-PERF:${Thread.currentThread().name}] $tag | $msg")
}
// endregion
/** /**
* 月度日历分页器HorizontalPager 实现无限左右滑动切换月份 * 月度日历分页器HorizontalPager 实现无限左右滑动切换月份
@ -60,9 +52,6 @@ fun CalendarPager(
pagerState: PagerState, pagerState: PagerState,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
var recomposeCount by remember { mutableIntStateOf(0) }
recomposeCount++
pagerPerfLog("CalendarPager", "composition #$recomposeCount selectedDate=$selectedDate collapseProgress=$collapseProgress")
val initialYear = remember { today.year } val initialYear = remember { today.year }
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
@ -83,7 +72,6 @@ fun CalendarPager(
flingBehavior = PagerDefaults.flingBehavior(state = pagerState), flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
modifier = modifier modifier = modifier
) { page -> ) { page ->
val pageComposeStart = System.nanoTime()
val pageOffset = abs(pagerState.currentPageOffsetFraction) val pageOffset = abs(pagerState.currentPageOffsetFraction)
val isCurrentPage = page == pagerState.currentPage val isCurrentPage = page == pagerState.currentPage
val alpha = if (isCurrentPage) { val alpha = if (isCurrentPage) {
@ -122,7 +110,5 @@ fun CalendarPager(
onRowHeightMeasured = onRowHeightMeasured, onRowHeightMeasured = onRowHeightMeasured,
modifier = Modifier.alpha(alpha) modifier = Modifier.alpha(alpha)
) )
val pageComposeMs = (System.nanoTime() - pageComposeStart) / 1_000_000.0
pagerPerfLog("CalendarPager", "page=$page year=$year month=$month alpha=${"%.2f".format(alpha)} elapsed=${"%.3f".format(pageComposeMs)}ms")
} }
} }

View File

@ -9,9 +9,7 @@ import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
@ -24,11 +22,6 @@ import kotlinx.datetime.plus
import plus.rua.project.ShiftKind import plus.rua.project.ShiftKind
import kotlin.math.abs import kotlin.math.abs
// region 性能监控工具
private fun weekPerfLog(tag: String, msg: String) {
println("[WEEK-PERF:${Thread.currentThread().name}] $tag | $msg")
}
// endregion
/** /**
* 周视图分页器折叠状态下显示选中日期所在周支持左右滑动切换周 * 周视图分页器折叠状态下显示选中日期所在周支持左右滑动切换周
@ -51,9 +44,6 @@ fun WeekPager(
showLegalHoliday: Boolean, showLegalHoliday: Boolean,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
var recomposeCount by remember { mutableIntStateOf(0) }
recomposeCount++
weekPerfLog("WeekPager", "composition #$recomposeCount selectedDate=$selectedDate")
val initialWeekMonday = remember { selectedDate.toWeekMonday() } val initialWeekMonday = remember { selectedDate.toWeekMonday() }
val pagerState = rememberPagerState( val pagerState = rememberPagerState(
initialPage = START_PAGE, initialPage = START_PAGE,
@ -82,7 +72,6 @@ fun WeekPager(
flingBehavior = PagerDefaults.flingBehavior(state = pagerState), flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
modifier = modifier modifier = modifier
) { page -> ) { page ->
val pageStart = System.nanoTime()
val pageOffset = abs(pagerState.currentPageOffsetFraction) val pageOffset = abs(pagerState.currentPageOffsetFraction)
val isCurrentPage = page == pagerState.currentPage val isCurrentPage = page == pagerState.currentPage
val alpha = if (isCurrentPage) { val alpha = if (isCurrentPage) {
@ -112,7 +101,5 @@ fun WeekPager(
) )
} }
} }
val pageMs = (System.nanoTime() - pageStart) / 1_000_000.0
weekPerfLog("WeekPager", "page=$page weekMonday=$weekMonday elapsed=${"%.3f".format(pageMs)}ms")
} }
} }

View File

@ -25,9 +25,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@ -52,12 +50,6 @@ import plus.rua.project.composeTraceEndSection
private val WEEKDAY_LABELS = listOf("", "", "", "", "", "", "") private val WEEKDAY_LABELS = listOf("", "", "", "", "", "", "")
// region 性能监控工具
private fun yearPerfLog(tag: String, msg: String) {
println("[YEAR-PERF:${Thread.currentThread().name}] $tag | $msg")
}
// endregion
private data class MiniMonthColors( private data class MiniMonthColors(
val titleSelected: Color, val titleSelected: Color,
val titleNormal: Color, val titleNormal: Color,
@ -90,10 +82,6 @@ fun YearGridView(
animatedVisibilityScope: AnimatedVisibilityScope, animatedVisibilityScope: AnimatedVisibilityScope,
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
val yearGridStart = System.nanoTime()
var yearGridRecomposeCount by remember { mutableIntStateOf(0) }
yearGridRecomposeCount++
yearPerfLog("YearGridView", "composition #$yearGridRecomposeCount year=$year selectedMonth=$selectedMonth")
composeTraceBeginSection("YearGridView:$year") composeTraceBeginSection("YearGridView:$year")
// P0-F: 主题色在 YearGridView 级别一次性读取并缓存 // P0-F: 主题色在 YearGridView 级别一次性读取并缓存
@ -208,8 +196,6 @@ fun YearGridView(
} }
} }
composeTraceEndSection() composeTraceEndSection()
val yearGridTotalMs = (System.nanoTime() - yearGridStart) / 1_000_000.0
yearPerfLog("YearGridView", "END year=$year elapsed=${"%.3f".format(yearGridTotalMs)}ms")
} }
/** /**
@ -322,7 +308,6 @@ private data class MiniDayData(
@Suppress("DEPRECATION") // monthNumber 无替代 API @Suppress("DEPRECATION") // monthNumber 无替代 API
private fun generateMiniMonthDays(year: Int, month: Int): List<MiniDayData> { private fun generateMiniMonthDays(year: Int, month: Int): List<MiniDayData> {
val start = System.nanoTime()
composeTraceBeginSection("generateMiniMonthDays:$year-$month") composeTraceBeginSection("generateMiniMonthDays:$year-$month")
val firstOfMonth = LocalDate(year, month, 1) val firstOfMonth = LocalDate(year, month, 1)
val offset = firstOfMonth.dayOfWeek.ordinal val offset = firstOfMonth.dayOfWeek.ordinal
@ -340,8 +325,6 @@ private fun generateMiniMonthDays(year: Int, month: Int): List<MiniDayData> {
) )
} }
composeTraceEndSection() composeTraceEndSection()
val elapsedMs = (System.nanoTime() - start) / 1_000_000.0
yearPerfLog("generateMiniMonthDays", "$year-$month rows=$rows totalDays=$totalDays elapsed=${"%.3f".format(elapsedMs)}ms")
return result return result
} }