Skip to content

Prevent periodic database vacuuming on Android 17+ - #8319

Merged
jmartinesp merged 2 commits into
developfrom
fix/stop-periodic-database-vacuuming-on-android-17
Dec 2, 2026
Merged

jmartinesp merged 2 commits into
developfrom
fix/stop-periodic-database-vacuuming-on-android-17

Conversation

@jmartinesp

@jmartinesp jmartinesp commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Content

What the title says.

Motivation and context

On Android, when we VACUUM a sqlite DB, this is loaded fully into RAM because of how the sqlite3 binary is built for the platform.

On Android 17+, there are native memory limits too, which means an app using too much RAM even with outside the JVM can get silently killed by the OS.

With large databases, like the event cache or the media ones once they grow for a long while, periodic vacuuming can mean loading GBs into RAM, and the app will crash.

There is also matrix-org/matrix-rust-sdk#7585 to disable these operations in the SDK when rooms or medias are removed from the databases. We should use incremental vacuuming instead, but that's way more complex and needs thorough testing.

Tests

Not easy to test: you'd have to use an emulator or real device in Android 17, then have a DB which has grown quite large and allow the vacuum worker to run. Previously, this should have caused a crash, now you should see the new 'Skipping database vacuuming on Android 17+' warning log, and the DBs won't be vacuumed.

Vacuuming the DBs from the developer options screen should still cause the crash, if that happened before.

Checklist

  • I am aware of the etiquette.
  • This PR was made with the help of AI:
    • Yes. In this case, please get the PR reviewed by an AI (e.g. a GitHub AI reviewer, or /code-review run in a fresh session) before requesting a human review.
    • No.
  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly defines what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

On Android, when we VACUUM a sqlite DB, this is loaded fully into RAM because of how the sqlite3 binary is built for the platform.

On Android 17+, there are native memory limits too, which means an app using too much RAM even with outside the JVM can get silently killed by the OS.

With large databases, like the event cache or the media ones once they grow for a long while, periodic vacuuming can mean loading GBs into RAM, and the app will crash.
@jmartinesp jmartinesp added the PR-Bugfix For bug fix label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/PNoFfF

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.13%. Comparing base (b3f6920) to head (5440f00).

Files with missing lines Patch % Lines
...es/matrix/impl/workmanager/VacuumDatabaseWorker.kt 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8319      +/-   ##
===========================================
- Coverage    81.13%   81.13%   -0.01%     
===========================================
  Files         2906     2906              
  Lines        87614    87619       +5     
  Branches     11897    11898       +1     
===========================================
  Hits         71088    71088              
- Misses       11889    11894       +5     
  Partials      4637     4637              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jmartinesp
jmartinesp marked this pull request as ready for review December 2, 2026 09:35
@jmartinesp
jmartinesp requested a review from a team as a code owner December 2, 2026 09:35
@jmartinesp
jmartinesp requested review from ganfra and removed request for a team December 2, 2026 09:35
On Android, when we VACUUM a sqlite DB, this is loaded fully into RAM because of how the sqlite3 binary is built for the platform.

On Android 17+, there are native memory limits too, which means an app using too much RAM even with outside the JVM can get silently killed by the OS.

With large databases, like the event cache or the media ones once they grow for a long while, periodic vacuuming can mean loading GBs into RAM, and the app will crash.
@jmartinesp
jmartinesp force-pushed the fix/stop-periodic-database-vacuuming-on-android-17 branch from cee4b91 to 5440f00 Compare December 2, 2026 09:40

@bmarty bmarty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

"Skipping database vacuuming on Android 17+, as this can cause the app to be killed by the system due to excessive memory usage. " +
"See https://developer.android.com/about/versions/17/behavior-changes-17"
)
return Result.success()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe also add (not replace) this test on scheduleDatabaseVacuum()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about doing that too, but this is a stopgap measure until we get a proper fix in the SDK, so I wanted to change as little code as possible since we'll revert it later.

@jmartinesp
jmartinesp merged commit a9227e7 into develop Dec 2, 2026
30 of 31 checks passed
@jmartinesp
jmartinesp deleted the fix/stop-periodic-database-vacuuming-on-android-17 branch December 2, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants