Skip to content

Conversation

@lemnik
Copy link
Contributor

@lemnik lemnik commented Jan 6, 2026

Goal

Remove the heartbeat lock in the AppHang plugin to avoid possibly locking the main thread when the monitor holds the lock at the same time.

Design

Replaced the lock & condition signalling with the park/unpark primitives. These only allow a single "block" / "unblock" behaviour, but the "parked" thread suits our use-case significantly better. This should reduce the overhead on the main thread.

Changes

  • Replaced the lock & condition with park/unpark
  • Replaced the elapsedRealtime clock with uptimeMillis which doesn't tick during deep sleeps, avoiding deep sleep triggering false-positive AppHangs
  • Moved the heartbeat re-posting to the monitor thread so that the heartbeat, improving the throughput on the main thread
sequenceDiagram
    activate monitor
    monitor->>main: heartbeat
    deactivate monitor
    activate main
    main->>monitor: unpark
    deactivate main
    activate monitor
    monitor->>main: heartbeat
    deactivate monitor
    activate main
    main->>monitor: unpark
    deactivate main
    activate monitor
Loading

Testing

Relied on existing tests.

@lemnik lemnik requested a review from YYChen01988 as a code owner January 6, 2026 16:53
@lemnik lemnik force-pushed the PLAT-15439/remove-heartbeat-lock branch from 63d7fbb to b9d7a25 Compare January 6, 2026 16:53
@bugsnagbot
Copy link
Collaborator

bugsnagbot commented Jan 6, 2026

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1842.46 1603.54
arm64_v8a 651.52 409.86
armeabi_v7a 594.18 352.52
x86 725.23 483.57
x86_64 696.57 454.9

Generated by 🚫 Danger

YYChen01988
YYChen01988 previously approved these changes Jan 12, 2026
Copy link
Contributor

@YYChen01988 YYChen01988 left a comment

Choose a reason for hiding this comment

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

LGTM

@lemnik lemnik force-pushed the PLAT-15439/remove-heartbeat-lock branch from 9912416 to abbe723 Compare January 12, 2026 14:32
@lemnik lemnik merged commit f82c73c into next Jan 15, 2026
42 checks passed
@lemnik lemnik deleted the PLAT-15439/remove-heartbeat-lock branch January 15, 2026 11:12
@lemnik lemnik mentioned this pull request Jan 19, 2026
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.

5 participants