Skip to content

perf: optimize hook startup and worker lifecycle - #1687

Open
tryigit wants to merge 14 commits into
ReChronoRain:mainfrom
tryigit:perf/runtime-startup-lifecycle
Open

tryigit wants to merge 14 commits into
ReChronoRain:mainfrom
tryigit:perf/runtime-startup-lifecycle

Conversation

@tryigit

@tryigit tryigit commented Sep 5, 2026

Copy link
Copy Markdown

Summary

This is a focused runtime performance, lifecycle, and fork-CI hardening pass for shared hook initialization infrastructure.

Changes

  • Avoid busy-spinning in ContextUtils.getWaitContext() when the application context is not ready yet.
    • use monotonic uptime for the timeout
    • retry at a short interval instead of repeatedly reflecting in a tight loop
    • preserve thread interruption
  • Keep the shared worker pool alive for initialization work, while allowing idle core threads to retire after 30 seconds.
  • Serialize worker submissions with shutdown/hot-reload cleanup so tasks cannot race a closing executor and fail with RejectedExecutionException.
  • Route current shared-pool call sites through the managed submission path instead of retaining raw executor instances.
  • Fix the getSystemUiContext() fallback to invoke the method that was actually resolved instead of calling getSystemContext() a second time.
  • Resolve target package metadata once when creating the DexKit cache and retain the full 64-bit longVersionCode.
    • removes duplicate PackageManager lookups during cache setup
    • avoids losing version-based cache invalidation when a package version code exceeds Int.MAX_VALUE
  • Make fork PR validation safe and self-contained:
    • grant the build job only contents: read and packages: read
    • warm the Gradle dependency cache from the trusted base commit while the package token is available
    • check out the PR merge commit afterwards and build it with --offline, so PR-controlled Gradle code does not receive github.token
    • allow offline Gradle configuration without package credentials
    • skip the secret-dependent Telegram debug-upload job for fork PRs

Expected impact

  • Lower CPU pressure during very early process startup when ActivityThread.currentApplication() is temporarily unavailable.
  • Less executor churn and lower idle thread/stack RAM in long-lived hooked processes.
  • No submission-vs-shutdown race during hot reload or concurrent initialization.
  • Slightly cheaper and more robust DexKit cache initialization.
  • External/fork PRs can reach a real Gradle build without exposing package credentials to PR-controlled build logic.

Scope

No feature fingerprints or hook targets are changed. Runtime changes are limited to shared startup, worker lifecycle, context resolution, and DexKit cache metadata handling. CI changes are limited to least-privilege package access, trusted dependency warmup, offline PR validation, and secret-dependent notification gating.

@codacy-production

codacy-production Bot commented Sep 5, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 minor

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
CodeStyle 2 minor

View in Codacy

🟢 Metrics 4 complexity

Metric Results
Complexity 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant