Skip to content

Reduce AppHangPlugin heartbeat overheads#2395

Merged
lemnik merged 1 commit intonextfrom
PLAT-15739/apphang-reduced-overhead
Mar 2, 2026
Merged

Reduce AppHangPlugin heartbeat overheads#2395
lemnik merged 1 commit intonextfrom
PLAT-15739/apphang-reduced-overhead

Conversation

@lemnik
Copy link
Copy Markdown
Contributor

@lemnik lemnik commented Feb 27, 2026

Goal

Reduce the CPU load (and "spamminess") of the heartbeat messages posted by the AppHangPlugin.

Design

Restructured the heartbeat such that:

  • Heartbeats only adjust the "last heartbeat" timestamps
  • Heartbeats are triggered by the monitor thread on a half-interval to the first "app might be hanging" time (either when we start sampling, or when we report an AppHang)

The heartbeats are also now triggered after appropriate delays (and only if there is no heartbeat message already on the queue), with the delay being calculated based on whether the monitor thread considers the app to be:

  • running normally (wait for a heartbeat interval)
  • stuck and requiring stack sampling (wait for a stack sample interval)
  • within an app hang (wait until the next heartbeat)
  • after an app hang and within the cooldown (wait for the cooldown period)

The "heartbeat interval" is half of the appHangThreshold or stackSamplingThresholdMillis (if configured):

    private val heartbeatInterval =
        if (isSamplingEnabled) samplingThresholdMillis / 2
        else appHangThresholdMillis / 20

Testing

Manual testing more complex scenarios with some dedicated message queue debugging added. Relied on existing tests continuing to pass for the overall plugin logic.

@bugsnagbot
Copy link
Copy Markdown
Collaborator

bugsnagbot commented Feb 27, 2026

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1851.29 1608.64
arm64_v8a 659.71 413.95
armeabi_v7a 598.28 352.52
x86 729.33 483.57
x86_64 700.66 459.0

Generated by 🚫 Danger

@lemnik lemnik force-pushed the PLAT-15739/apphang-reduced-overhead branch 2 times, most recently from 5308e9d to c111bb6 Compare February 27, 2026 08:46
@lemnik lemnik force-pushed the PLAT-15739/apphang-reduced-overhead branch from c111bb6 to d95eefe Compare February 27, 2026 11:07
Copy link
Copy Markdown
Contributor

@hamudi-ahmed hamudi-ahmed 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 merged commit 575ed4b into next Mar 2, 2026
81 checks passed
@lemnik lemnik deleted the PLAT-15739/apphang-reduced-overhead branch March 2, 2026 13:12
@lemnik lemnik mentioned this pull request Mar 2, 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.

4 participants