From 373aa7d74045feaa594699ddb98e4863b136bf7d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 27 Jun 2026 19:56:37 +0000 Subject: [PATCH] perf: keep ColorScheme.isLight O(1) after accent-color change isLight fans out to hundreds of themed-color getters on hot note/chat/feed render paths. The accent-color work had switched it to background.luminance(), which adds per-call gamma math. Since the accent never touches background (only primary/secondary) and the dark palette's background is exactly Color.Black, a single reference comparison is just as accent-robust and restores the original constant-time cost. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01REGsru6cnm6wUzqm12Rh2d --- .../java/com/vitorpamplona/amethyst/ui/theme/Theme.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt index a53fa12c30..39f561d15d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/theme/Theme.kt @@ -46,7 +46,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.graphics.luminance import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity @@ -423,10 +422,12 @@ val MarkDownStyleOnLight = ), ) -// Derived from background luminance instead of a fixed primary so the check keeps working -// when the user picks a non-purple accent color (only primary/secondary change, not background). +// Compared against the dark palette's background instead of a fixed primary so the check keeps +// working when the user picks a non-purple accent (accent only changes primary/secondary, never +// background). Kept as a single reference comparison because this getter fans out to hundreds of +// themed-color call sites on hot rendering paths — luminance()/etc. would add real per-frame cost. val ColorScheme.isLight: Boolean - get() = background.luminance() > 0.5f + get() = background != Color.Black // The accent-derived tints below are computed from the live scheme's primary so they follow // the selected accent color. Color is an inline value class, so these copies don't allocate.