Skip to content

ADFA-2537: intialize parts of termux application loader on IO dispatcher - #844

Merged
itsaky-adfa merged 8 commits into
stagefrom
fix/ADFA-2537
Jan 21, 2026
Merged

ADFA-2537: intialize parts of termux application loader on IO dispatcher#844
itsaky-adfa merged 8 commits into
stagefrom
fix/ADFA-2537

Conversation

@itsaky-adfa

@itsaky-adfaitsaky-adfa commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

See ADFA-2537 for more details.

@itsaky-adfa
itsaky-adfa requested a review from a teamJanuary 16, 2026 11:47
@itsaky-adfaitsaky-adfa self-assigned this Jan 16, 2026
@coderabbitai

coderabbitaiBot commented Jan 16, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Release Notes

Changes

  • Termux application loader: Moved IO-bound initialization (directory checks/creation, server setup, environment init) onto Dispatchers.IO to avoid main-thread blocking.
  • Color scheme provider: IDEColorSchemeProvider.init() now runs on Dispatchers.IO since schemes are file-backed.
  • setLogConfig: Converted to a suspending function (private suspend fun setLogConfig(context: Context)) and performs IO on Dispatchers.IO.
  • Coroutine launcher defaults: Explicit Dispatchers.Default used for several coroutine launches in IDEApplication to ensure expected background execution.

Risks & Best Practice Considerations

  • ⚠️ Early return from withContext: Using return@withContext exits only the IO block, not the enclosing function—critical errors may not stop subsequent initialization. Recommend propagating failures (throw/cancel) or returning from the outer function to prevent partial startup.
  • ⚠️ Fire-and-forget init: IDEColorSchemeProvider.init() is launched without awaiting; callers that assume synchronous completion may encounter race conditions. Consider making it suspending or awaiting completion where needed.
  • ⚠️ API/behavior change: setLogConfig became suspending; ensure all internal call sites are updated and lifecycle assumptions remain valid.
  • ✅ Dispatcher usage: IO-bound work moved to Dispatchers.IO and CPU work to Dispatchers.Default, aligning with coroutine best practices and reducing main-thread blocking.

Walkthrough

Coroutines and IO context usage were made explicit: IDEColorSchemeProvider.init() is launched on Dispatchers.IO; TermuxApplicationLoader moves initialization and log configuration into Dispatchers.IO using withContext and converts setLogConfig into a suspending function.

Changes

Cohort / File(s)Summary
Credential-protected app loader
app/src/main/java/com/itsaky/androidide/app/CredentialProtectedApplicationLoader.kt
Coroutine launch now uses Dispatchers.IO for IDEColorSchemeProvider.init(); added comments noting color schemes are file-backed and init runs on IO dispatcher.
Termux app loader & logging
app/src/main/java/com/itsaky/androidide/app/TermuxApplicationLoader.kt
Main initialization moved into withContext(Dispatchers.IO) (directory checks/creation, server setup, environment init). setLogConfig changed to private suspend fun and performs IO work inside withContext(Dispatchers.IO).
Application-level coroutine launches
app/src/main/java/com/itsaky/androidide/app/IDEApplication.kt
Several coroutine launches now explicitly specify Dispatchers.Default instead of the implicit dispatcher.

Sequence Diagram(s)

sequenceDiagram
participant Main as Main Thread
participant IO as IO Dispatcher
participant Color as IDEColorSchemeProvider
participant FS as FileSystem
participant Server as TermuxServer
participant Env as Environment
participant Log as LogConfig
Main->>IO: launch CredentialProtectedApplicationLoader.init()
IO->>Color: IDEColorSchemeProvider.init()
Color-->>IO: init complete
IO-->>Main: credential-protected init done
Main->>IO: TermuxApplicationLoader.load() (withContext(IO))
IO->>FS: check/create directories
FS-->>IO: dirs ready
IO->>Server: setup/start server
Server-->>IO: server running
IO->>Env: initialize environment
Env-->>IO: env ready
IO->>Log: setLogConfig() (suspend, IO)
Log-->>IO: log level applied
IO-->>Main: Termux load() complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • jomen-adfa
  • jatezzz

Poem

🐇 I hopped to shift tasks off the main,

Moved colors and servers where files reign,
IO now dances in quieter threads,
Logs hum softly while startup treads,
Happy loaders, nimble and sane.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check nameStatusExplanationResolution
Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check nameStatusExplanation
Title check✅ PassedThe title directly describes the main change: moving Termux application loader initialization to the IO dispatcher to improve performance by offloading IO-bound operations from the main thread.
Description check✅ PassedThe description references the Jira issue ADFA-2537 which provides context, though minimal details are in the PR body itself. This relates to the changeset's dispatcher optimization work.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@itsaky-adfa
itsaky-adfa merged commit a49765e into stageJan 21, 2026
2 checks passed
@itsaky-adfa
itsaky-adfa deleted the fix/ADFA-2537 branch January 21, 2026 11:29
jatezzz pushed a commit that referenced this pull request Jun 22, 2026
…her (#844)
* fix: initialize parts of termux loader on bg threads
* fix: dispatch credential-prot loader on default dispatcher after unlock
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
Sign up for freeto 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.

2 participants

@itsaky-adfa@jomen-adfa