Speed up startup by fetching Vencord in the background #1

Merged
nin0 merged 3 commits from himkad/VendroidEnhanced:perf/background-vencord-fetch-rebased into main 2026-10-11 15:50:01 -04:00
Contributor
  • Vencord is now fetched in the background. Before, fetchVencord ran in onCreate and blocked the main thread with a network download and a read of a multi-MB file. That froze the splash screen and needed the StrictMode.permitNetwork workaround (explodeAndroid), which this PR removes. Discord now loads only after the runtime is ready to inject.
    • If the fetch fails, the user sees a toast and Discord loads without Vencord. Before, this failure was silent.
    • HttpClient.fetch now has timeouts: 10s to connect and 30s to read. Without them, a stalled network could leave the splash screen up forever.
    • The runtime fields are now @Volatile and fetchVencord is @Synchronized. This stops a recreated activity from starting a second download while the first is still writing vencord.js.
    • Toasts inside fetchVencord now go through runOnUiThread, since the function no longer runs on the main thread.
  • VWebviewClient intercepts fewer requests. It now intercepts only the main document (to strip the CSP) and .css files from raw.githubusercontent.com (to fix their text/plain + nosniff Content-Type so themes apply). All other CSS and subresources go through the WebView's own disk cache instead of being refetched on every load.

Dependencies

  • android-gif-drawable bumped from 1.2.28 to 1.2.32. The old version shipped libpl_droidsonroids_gif.so with 4 KB-aligned LOAD segments, which fails Android's 16 KB page-size ELF alignment check.

Tested:

  • Cold start with a cached bundle: the splash screen stays responsive and Vencord loads
  • Cold start with no cached bundle on a slow or offline network: a timeout or failure toast appears and Discord loads without Vencord
  • Safe mode: Discord loads, the "Vencord won't be loaded" toast appears
  • A GitHub raw theme still applies through QuickCSS or theme links
  • The app runs on a 16 KB page-size device or emulator
- Vencord is now fetched in the background. Before, fetchVencord ran in onCreate and blocked the main thread with a network download and a read of a multi-MB file. That froze the splash screen and needed the StrictMode.permitNetwork workaround (explodeAndroid), which this PR removes. Discord now loads only after the runtime is ready to inject. - If the fetch fails, the user sees a toast and Discord loads without Vencord. Before, this failure was silent. - HttpClient.fetch now has timeouts: 10s to connect and 30s to read. Without them, a stalled network could leave the splash screen up forever. - The runtime fields are now @Volatile and fetchVencord is @Synchronized. This stops a recreated activity from starting a second download while the first is still writing vencord.js. - Toasts inside fetchVencord now go through runOnUiThread, since the function no longer runs on the main thread. - VWebviewClient intercepts fewer requests. It now intercepts only the main document (to strip the CSP) and .css files from raw.githubusercontent.com (to fix their text/plain + nosniff Content-Type so themes apply). All other CSS and subresources go through the WebView's own disk cache instead of being refetched on every load. Dependencies - android-gif-drawable bumped from 1.2.28 to 1.2.32. The old version shipped libpl_droidsonroids_gif.so with 4 KB-aligned LOAD segments, which fails Android's 16 KB page-size ELF alignment check. Tested: - [x] Cold start with a cached bundle: the splash screen stays responsive and Vencord loads - [x] Cold start with no cached bundle on a slow or offline network: a timeout or failure toast appears and Discord loads without Vencord - [x] Safe mode: Discord loads, the "Vencord won't be loaded" toast appears - [x] A GitHub raw theme still applies through QuickCSS or theme links - [x] The app runs on a 16 KB page-size device or emulator
fetchVencord blocked onCreate with a network download and multi-MB file
read, freezing startup (and requiring the StrictMode permitNetwork hack).
Run it on a background thread and defer loading Discord until the runtime
is ready to inject, so the splash screen stays responsive. Toasts inside
fetchVencord now go through runOnUiThread since it no longer runs on the
main thread. If the fetch fails, show a toast instead of silently loading
Discord without Vencord.

Since the splash screen now waits on the fetch, give HttpClient.fetch
connect/read timeouts so a stalled network can't hang it forever. The
runtimes are now @Volatile and fetchVencord is @Synchronized, so a
recreated activity can't start a second download that races the first
one writing vencord.js.
Stripping the CSP is only needed for the main document, and the CSS
override is only needed for themes on raw.githubusercontent.com, which
serves them as text/plain with nosniff so the WebView would otherwise
refuse to apply them. Letting all other CSS and subresources go through
the WebView's own disk cache avoids refetching them on every load.
1.2.28 shipped libpl_droidsonroids_gif.so with 4 KB-aligned LOAD
segments, which fails Android's 16 KB ELF alignment check.
nin0 approved these changes 2026-10-10 06:49:19 -04:00
nin0 left a comment

PR looks great

just a few questions, not accusing you of anything

  • what’s your discord user ID, so I can give you the contributor badge
  • how much AI if any was involved in this PR
PR looks great just a few questions, not accusing you of anything - what’s your discord user ID, so I can give you the contributor badge - how much AI if any was involved in this PR
Owner

also, did you test the PR on an emulator or real device

also, did you test the PR on an emulator or real device
Author
Contributor

Hey there,

  • I prefer to stay anonymous :)
  • I def used quite a bit of claude which was especially useful for finding potential gaps. I wholly submit to your judgement about whether that is allowed in your project -- apologies if this is against contribution rules, I didn't see it anywhere. I don't push anything I haven't read the diffs of though.
  • I tested with a real Pixel 8
Hey there, * I prefer to stay anonymous :) * I def used quite a bit of claude which was especially useful for finding potential gaps. I wholly submit to your judgement about whether that is allowed in your project -- apologies if this is against contribution rules, I didn't see it anywhere. I don't push anything I haven't read the diffs of though. * I tested with a real Pixel 8
Owner

Did you use claude more as an assistant or simply prompted it to write the code then did the pr

Did you use claude more as an assistant or simply prompted it to write the code then did the pr
Author
Contributor

The former lol

The former lol
nin0 force-pushed perf/background-vencord-fetch-rebased from e8ec61d48a to 9e3995fa41 2026-10-11 15:49:24 -04:00 Compare
nin0 merged commit e0949fe544 into main 2026-10-11 15:50:01 -04:00
Owner

thanks for the contribution, it should pretty soon be released

thanks for the contribution, it should pretty soon be released
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nin0/VendroidEnhanced!1
No description provided.