Skip to content

perf(android): reduce Compose recomposition and virtual list churn - #427

Merged
tiensonqin merged 2 commits into
mainfrom
devin/1795783490-android-compose-perf
Nov 27, 2026
Merged

tiensonqin merged 2 commits into
mainfrom
devin/1795783490-android-compose-perf

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Reduce Android Jetpack Compose recomposition, state allocation, and scroll-jump overhead on hot list/editing updates (no public API, wire-contract, or non-Android changes):

  • LuiBackend (@Stable): allow Compose to skip unchanged LuiNodeView(backend, id) calls.
  • LuiNodeView / LuiChromeSurface:
    • Check child kinds via backend.nodeKind(it) instead of backend.node(it)?.kind so parent containers do not subscribe to every child's snapshot state.
    • Fast-path LuiChromeSurface when contextMenuId == null (avoids per-node Box and two mutableStateOf allocations) and skip filtering node.children when no auxiliary contextMenu/swipeActions child is present.
  • LuiRender (luiChrome, luiGestures, LuiThemeScope):
    • Skip luiThemeColor lookups when background/border-color are unset.
    • Early-return from luiGestures when disabled or no gestures/context-menu/pointer handlers are active, avoiding unnecessary mutableStateOf/combinedClickable/pointerInput allocations.
    • Fast-path LuiThemeScope when a node declares no theme/typography/foreground overrides and LocalLuiThemeDark.current != null, and only wrap containers in MaterialExpressiveTheme when theme-mode is set.
  • LuiVirtualList:
    • Introduce @Stable RowHeightStore, RowIndexRef, and LuiVirtualRowItem so unchanged virtual rows skip recomposition when sibling indices shift.
    • Scroll pinned items near the bottom edge incrementally (scrollBy / bottom-aligned offset) instead of jumping them to the top of the viewport.

Verification

  • platform/android/gradlew --no-daemon -p platform/android :lui:testDebugUnitTest :lui:lintDebug --console=plain — BUILD SUCCESSFUL.
  • Verified in logseq/mobile 500-block repeated-Enter Android benchmark (median reduced to 90–98ms, p95 132–135ms, native_editor_instances = 1).

Link to Devin session: https://app.devin.ai/sessions/fd01f05d7f35485d99e7bbca3ea1a87d
Open in Devin Desktop: https://app.devin.ai/desktop/session/fd01f05d7f35485d99e7bbca3ea1a87d?variant=devin
Requested by: @tiensonqin


🟢 Devin fixed all 6 findings · Follow Devin's work

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 6 findings. Devin automatically fixed all 6 findings.

Fixed by Devin (6)
  • Standalone popover anchor bounds — Preserved the enclosing Box(propagateMinConstraints = true) wrapper for standalone LuiNodeKind.popover nodes in LuiChromeSurface.
  • Missing Expressive theme in Drive — Keep MaterialExpressiveTheme mounted on root containers (ambientDark == null) in addition to nodes declaring theme-mode, so hosts like Drive sample still receive the Expressive theme.
  • Unobservable stable backend properties — Backed LuiBackend.filePathResolver with mutableStateOf so @stable change-notification guarantees hold even if replaced after mounting.
  • Theme switches drop editor focus — Removed the conditional CompositionLocalProvider branch inside LuiThemeScope themedContent so toggling theme-mode/foreground never remounts content or drops editor focus.
  • Pinned editor remains partly offscreen — After bottom-aligned scrollToItem for a pinned row below the viewport, await one frame and scrollBy any remaining overflow if the measured row is taller than the estimate.
  • Moved rows leave stale heights — Track lastHeight on RowIndexRef and immediately update heightStore.heights[index] when a keyed row shifts index without resizing.

View findings in Devin Review · Follow Devin's work

Devin Review

@tiensonqin
tiensonqin merged commit 7eaa9bf into main Nov 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant