Skip to content

Settings→Library back navigation causes a reproducible ~780ms main-thread stall + rendering artifact #653

Open

Description

@robster7674

Summary

Separate from #642 (playback, fixed in #649) — navigating from Settings back to Library causes a real, reproducible, near-identical ~780ms main-thread stall on every occurrence, with a visible rendering artifact on the way back. Confirmed via two adb logcat captures with a tight, isolated repro (Library → ⋮ → Settings → scroll → back, twice).

Evidence

Both cycles show a genuine silence on the app's PID — zero SurfaceFlinger/Choreographer/BLASTBufferQueue activity, not an animation playing out — between the back tap registering and LibraryScannerImpl's re-scan (triggered by LibraryScreen's ON_RESUME observer) actually starting:

  • Cycle 1: back touch-up 06:55:44.470 → LibraryScanner Scan started 06:55:45.253 = 783ms
  • Cycle 2: back touch-up 06:56:03.063 → LibraryScanner Scan started 06:56:03.842 = 779ms

The near-identical duration across two independent occurrences points to a deterministic, fixed-cost blocking call — not general GC/scheduling jitter.

Ruled out by code reading

  • SettingsScreen/SettingsViewModel have no DisposableEffect/onCleared work — nothing to block on teardown.
  • LibraryScreen's ON_RESUME observer → LibraryViewModel.refresh() → triggerScan(): previousJob?.cancelAndJoin() should be near-instant (the prior scan job, from cold start, is long complete by the time Settings is visited) and mutex acquisition should be uncontended.
  • LibraryViewModel is not recreated on this navigation (Library stays on the back stack the whole time Settings is pushed) — ruled out a double-init-triggered scan race.

So the stall is somewhere between the back-stack pop/transition and refresh() actually being invoked — a gap not visible from logcat's system-level signals alone.

Not yet confirmed

Earlier speculative hypothesis (SecureScreenEffect's reference-counted FLAG_SECURE toggle leaking) is not supported by this evidence — Settings/Library never call that effect, and the stall's precise, repeatable duration doesn't match a leaked-flag theory either. Leaving that hypothesis withdrawn pending real data.

Next step

Temporary diagnostic logging around the back-navigation/resume path (timestamped log lines at the ON_RESUME observer's entry, immediately before/after cancelAndJoin(), and immediately before scanMutex.withLock) to bisect exactly which segment of the ~780ms the time is actually spent in. Requires a new debug build for on-device repro + logcat.

Activity

  1. github-actions commented on Aug 26, 2026

    @github-actions
    Contributor

    Dev agent didn't triage this: this issue's author is associated with the repo as CONTRIBUTOR, and dev-agent.yml's trust gate requires OWNER, MEMBER, or COLLABORATOR before handing issue content to an agent with repo-write access (this repo is public — see docs/agent-team-pipeline.md's Trust boundary section). Re-applying status:ready-for-dev will not get past this — the check reads the issue's own author_association, not whoever applies the label. To move this forward: either have someone with at least write access to the repo trigger it manually (Actions → Dev Agent → Run workflow, with this issue's number as issue_number — GitHub itself already gates who can do that, so it's treated as trusted), or have the same content refiled by an OWNER/MEMBER/COLLABORATOR account.

  2. robster7674 commented on Aug 26, 2026

    @robster7674
    ContributorAuthor

    Diagnostic debug build with temporary timestamped logging (tag DIAG-SettingsStall) around the back-navigation/resume path built off diag/settings-back-nav-stall (not pushed — throwaway instrumentation, will be removed once this is root-caused) for a bisecting repro. Not yet root-caused; still open.

  3. robster7674 commented on Aug 26, 2026

    @robster7674
    ContributorAuthor

    Root cause found via a targeted diagnostic build

    Added timestamp checkpoints at every step of the suspected path (onBack → popBackStack() → ON_RESUME → triggerScan() → scan-flow start) and got two clean, consistent repros:

    segment cycle 1 cycle 2
    onBack tap → popBackStack() returns 2ms 2ms
    popBackStack() returns → ON_RESUME fires 932ms 894ms
    ON_RESUME → all of triggerScan() (job launch, cancelAndJoin(), scan flow's first emission) <1ms <1ms

    This clears every piece of app code I'd instrumented — LibraryViewModel.triggerScan(), the scan mutex/flow, and the NavHost composable lambdas themselves are all effectively instantaneous. 100% of the delay is between NavController.popBackStack() returning and the Library destination's lifecycle actually reaching ON_RESUME — i.e. inside Compose Navigation's / the platform's own back-transition machinery, before any of our code runs again.

    Correlating with the raw system log in that exact window (both repros, independently):

    ...WindowOnBackDispatcher: sendCancelIfRunning...
    ...RefreshRateModeManager: onBrightnessChangedLocked...
    ...RefreshRateModeManager: Schedule to change HFRmode=REFRESH_RATE_MODE_SEAMLESS ... DisableRefreshRateSwitchingVote=true
    ...SurfaceFlinger: HFR mode : 1
    ...HWComposer: ActiveConfigToHWC, ID : 4
    ...display: setActiveConfigWithConstraints:: HFR match - config: 4 ...
    ...display: Set Affinity CPU ID : 0..9   (HWC thread affinity reassigned across all cores)
                                  ⬇ ~800-900ms of total silence, system-wide, in logcat ⬇
    DIAG-SettingsStall: ON_RESUME fired
    

    That's the Samsung One UI display pipeline renegotiating the panel's refresh rate (idle→touch triggers a switch back to the "seamless"/high-refresh mode, forcing a fixed-Hz vote and reassigning compositor thread CPU affinity) landing at the exact moment our new destination needs a frame presented to become RESUMED. This same HFR switch event fires ~18 times over the full session (basically every idle→touch transition) but only stalls this badly when it lands concurrently with a nav back-transition needing to present a fresh frame — plain scrolling touches elsewhere settle in a few hundred ms with no visible impact.

    Checked our own code for anything that could be provoking or amplifying this: no setFrameRate/preferredRefreshRate/preferredDisplayModeId calls anywhere in the app, and LibravaultNavHost uses navigation-compose's stock composable {} with no custom enterTransition/exitTransition — so this isn't something our Kotlin is doing wrong in the traditional sense. It looks like an OEM (Samsung One UI) display-pipeline interaction that a stock Compose Navigation back-transition happens to expose on this hardware.

    Not something I can confidently "fix" with an app-code change without guessing — flagging for a decision on how to proceed (try a speculative mitigation like a custom pop transition/predictive-back tweak vs. try to reproduce on non-Samsung hardware to confirm scope vs. accept as a platform limitation).

    Diagnostic instrumentation stays on branch diag/settings-back-nav-stall (not pushed — throwaway, will be discarded).

  4. libravault-xyz commented on Aug 26, 2026

    @libravault-xyz
    Collaborator

    CI-based jank comparison: blocked by an unrelated, already-tracked infra bug

    Tried a device-agnostic secondary check: a new instrumented test (SettingsNavJankTest, black-box UiAutomator driver + dumpsys gfxinfo) run via CircleCI's ui-tests emulator job, once against current dev HEAD and once against the commit immediately before the two vault-unification merges (2f2ed85), to see whether composition itself got measurably heavier independent of the Samsung-specific mechanism already root-caused above.

    Both runs died identically before the test could execute — hit issue #582 (already open, already status:in-progress): AGP 8.9.1's bundled R8 is too old for Kotlin 2.2.10's metadata format, and chokes dexing core:vaultcontent's VaultDataSource$Factory for the androidTest APK. That class exists in both commits, unrelated to the vault-unification work, so this produced no signal either way on the jank question — not a regression finding, just an unrelated build-tooling wall. Not pursuing a workaround here since #582 is already someone else's in-progress fix.

    The manual on-device path (ab-test-settings-stall.sh, already shared) remains the one route that can actually produce comparative data, since it sideloads pre-built APKs directly and never touches this dexing step.

  5. libravault-xyz commented on Aug 27, 2026

    @libravault-xyz
    Collaborator

    Real-device A/B result: confirmed pre-existing device characteristic, not a regression

    Ran an automated on-device A/B test on the reporting Samsung phone: two diagnostic builds (current dev HEAD vs. the commit immediately before the #543/#604 vault-unification merges), each instrumented at every step of the suspected path, driven through 2 Settings→Library round-trips per build in one continuous logcat capture.

    Measured window: NavController.popBackStack() returning → the Library destination's next ON_RESUME firing (the same window two earlier manual real-device captures had already shown zero app-code activity in).

    Build Cycle delta
    pre-#543/#604 (baseline) 1 856ms
    pre-#543/#604 (baseline) 2 833ms
    dev HEAD (current) 1 901ms
    dev HEAD (current) 1 (extra pass) 853ms
    dev HEAD (current) 2 834ms

    All 5 samples land in a tight 833–901ms band, indistinguishable between baseline and current, and consistent with the ~780–900ms the two earlier manual captures found — both of which correlated the gap with Samsung's RefreshRateModeManager renegotiating the display refresh rate at exactly that moment (an OEM display-HAL mechanism, not reproducible on any generic emulator; a separate CircleCI-emulator A/B run on generic hardware also found no consistent current-vs-baseline gap, corroborating this).

    A CircleCI emulator A/B pass, an exhaustive code review of both suspect commits (af04059, 5816cfa), and now this real-device A/B all agree: the vault-unification work (#543/#604) did not introduce this stall. Re-scoping this issue from a regression/bug to a device-specific investigate-mitigation task — worth a look at Window.setFrameRate()/suggestFrameRate() to see whether the app can avoid forcing an idle→high-refresh-rate switch mid-transition, but this is no longer blocking or attributed to any specific commit.

    Filing a smaller, appropriately-scoped follow-up issue for that mitigation investigation and closing this one out as resolved-not-a-regression.

  6. libravault-xyz commented on Aug 27, 2026

    @libravault-xyz
    Collaborator

    Root-caused via real-device A/B test (see comment above): confirmed pre-existing Samsung One UI display-refresh-rate characteristic, not a regression from #543/#604 or any other code change. Follow-up mitigation investigation split out to #686.

  7. libravault-xyz commented on Aug 27, 2026

    @libravault-xyz
    Collaborator

    Reopening — premature to close. The stall-timing half is confirmed a pre-existing device characteristic (see A/B evidence above), but this issue's title also covers a rendering artifact, which was never separately re-verified as fixed or explained — only the timing was instrumented and measured. Also correcting the record: the 'extra unscripted back-tap' noted in the prior comment was the human tester manually pressing Back again, not an app-level phantom double-dispatch — striking that theory. Building a fresh plain (non-diagnostic) APK from latest dev HEAD now for a direct visual re-check of the rendering artifact.

  8. libravault-xyz commented on Aug 27, 2026

    @libravault-xyz
    Collaborator

    Confirmed by user on latest dev HEAD (e777ebe, plain non-diagnostic build): both the sluggish feel and the visual rendering artifact are still present. This is real and still open — the earlier A/B test only settled the timing question (stall duration is a pre-existing Samsung device characteristic, not a #543/#604 regression); it never characterized the visual artifact itself. Adding screen-recording capture to the on-device test harness next so the artifact can actually be seen and diagnosed rather than inferred from logcat timestamps.

  9. libravault-xyz commented on Aug 27, 2026

    @libravault-xyz
    Collaborator

    Root cause identified and fixed in PR #694 — the resume-triggered vault rescan (#96) was wired to LocalLifecycleOwner, which inside a NavHost destination fires ON_RESUME on every plain in-app back-navigation (Settings -> Library), not just on true app backgrounding. That's the spinner/artifact the user confirmed. Fix scopes it to ProcessLifecycleOwner instead. Separately tracked: #692, whether the scan itself is also slower on a real populated library (not yet confirmed either way).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions